com.googlecode.flickrjandroid.oauth.OAuthInterface Java Examples
The following examples show how to use
com.googlecode.flickrjandroid.oauth.OAuthInterface.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetAccessTokenTask.java From glimmr with Apache License 2.0 | 6 votes |
@Override protected OAuth doInBackground(String... params) { String oauthToken = params[0]; String oauthTokenSecret = params[1]; String verifier = params[2]; Flickr f = FlickrHelper.getInstance().getFlickr(); OAuthInterface oauthApi = f.getOAuthInterface(); try { return oauthApi.getAccessToken(oauthToken, oauthTokenSecret, verifier); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #2
Source File: Transport.java From flickr-uploader with GNU General Public License v2.0 | 6 votes |
public Response postJSON(String apiSharedSecret, List<Parameter> parameters) throws IOException, JSONException, FlickrException { boolean isOAuth = false; for (int i = parameters.size() - 1; i >= 0; i--) { if (parameters.get(i) instanceof OAuthTokenParameter) { isOAuth = true; break; } } parameters.add(new Parameter("nojsoncallback", "1")); parameters.add(new Parameter("format", "json")); if (isOAuth) { OAuthUtils.addOAuthParams(apiSharedSecret, OAuthInterface.URL_REST, parameters); } return post(OAuthInterface.PATH_REST, parameters); }
Example #3
Source File: Uploader.java From flickr-uploader with GNU General Public License v2.0 | 6 votes |
/** * Upload a photo from an InputStream. * * * @param imageName * @param in * @param photoId * @return photoId for sync mode or ticketId for async mode * @throws IOException * @throws FlickrException * @throws SAXException * @deprecated This is not working at moment! */ public String replace(String imageName, InputStream in, String photoId, boolean async) throws IOException, FlickrException, SAXException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, this.apiKey)); parameters.add(new Parameter("async", async ? "1" : "0")); parameters.add(new Parameter("photo_id", photoId)); parameters.add(new ImageParameter(imageName, in)); OAuthUtils.addOAuthToken(parameters); UploaderResponse response = (UploaderResponse) transport.replace(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } String id = ""; if (async) { id = response.getTicketId(); } else { id = response.getPhotoId(); } return id; }
Example #4
Source File: Uploader.java From flickr-uploader with GNU General Public License v2.0 | 6 votes |
/** * Upload a photo from an InputStream. * * @param imageName * @param in * @param photoId * @return photoId for sync mode or ticketId for async mode * @throws IOException * @throws FlickrException * @throws SAXException * @deprecated This is not working at moment! */ public String replace(String imageName, byte[] data, String photoId, boolean async) throws IOException, FlickrException, SAXException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, this.apiKey)); parameters.add(new Parameter("async", async ? "1" : "0")); parameters.add(new Parameter("photo_id", photoId)); parameters.add(new ImageParameter(imageName, data)); ; OAuthUtils.addOAuthToken(parameters); UploaderResponse response = (UploaderResponse) transport.replace(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } String id = ""; if (async) { id = response.getTicketId(); } else { id = response.getPhotoId(); } return id; }
Example #5
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 6 votes |
/** * Edit which photos are in the photoset. * * @param photosetId * The photoset ID * @param primaryPhotoId * The primary photo Id * @param photoIds * The photo IDs for the photos in the set * @throws IOException * @throws FlickrException * @throws JSONException */ public void editPhotos(String photosetId, String primaryPhotoId, String[] photoIds) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_EDIT_PHOTOS)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("photoset_id", photosetId)); parameters.add(new Parameter("primary_photo_id", primaryPhotoId)); parameters.add(new Parameter("photo_ids", StringUtilities.join(photoIds, ","))); OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
Example #6
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 6 votes |
/** * Create a new photoset. * * @param title * The photoset title * @param description * The photoset description * @param primaryPhotoId * The primary photo id * @return The new Photset * @throws IOException * @throws FlickrException * @throws JSONException */ public Photoset create(String title, String description, String primaryPhotoId) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_CREATE)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("title", title)); parameters.add(new Parameter("description", description)); parameters.add(new Parameter("primary_photo_id", primaryPhotoId)); OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } JSONObject photosetElement = response.getData().getJSONObject("photoset"); Photoset photoset = new Photoset(); photoset.setId(photosetElement.getString("id")); photoset.setUrl(photosetElement.getString("url")); return photoset; }
Example #7
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 6 votes |
/** * Modify the meta-data for a photoset. * * @param photosetId * The photoset ID * @param title * A new title * @param description * A new description (can be null) * @throws IOException * @throws FlickrException * @throws JSONException */ public void editMeta(String photosetId, String title, String description) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_EDIT_META)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("photoset_id", photosetId)); parameters.add(new Parameter("title", title)); if (description != null) { parameters.add(new Parameter("description", description)); } OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
Example #8
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 5 votes |
public void setPrimaryPhoto(String photosetId, String photoId) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_SET_PRIMARY_PHOTO)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("photoset_id", photosetId)); parameters.add(new Parameter("photo_id", photoId)); OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
Example #9
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 5 votes |
/** * Remove a photo from the set. * * @param photosetId * The photoset ID * @param photoId * The photo ID * @throws IOException * @throws FlickrException * @throws JSONException */ public void removePhoto(String photosetId, String photoId) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_REMOVE_PHOTO)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("photoset_id", photosetId)); parameters.add(new Parameter("photo_id", photoId)); OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
Example #10
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 5 votes |
/** * Set the order in which sets are returned for the user. * * This method requires authentication with 'write' permission. * * @param photosetIds * An array of Ids * @throws IOException * @throws FlickrException * @throws JSONException */ public void reorderPhotos(String photosetId, List<String> photoIds) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_REORDER_PHOTOS)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("photoset_id", photosetId)); parameters.add(new Parameter("photo_ids", StringUtilities.join(photoIds, ","))); OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
Example #11
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 5 votes |
/** * Set the order in which sets are returned for the user. * * This method requires authentication with 'write' permission. * * @param photosetIds * An array of Ids * @throws IOException * @throws FlickrException * @throws JSONException */ public void orderSets(String[] photosetIds) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_ORDER_SETS)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("photoset_ids", StringUtilities.join(photosetIds, ","))); OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
Example #12
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 5 votes |
/** * Delete the specified photoset. * * @param photosetId * The photoset ID * @throws IOException * @throws FlickrException * @throws JSONException */ public void delete(String photosetId) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_DELETE)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("photoset_id", photosetId)); OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
Example #13
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 5 votes |
/** * Add a photo to the end of the photoset. * <p/> * Note: requires authentication with the new authentication API with 'write' permission. * * @param photosetId * The photoset ID * @param photoId * The photo ID * @throws JSONException */ public void addPhoto(String photosetId, String photoId) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_ADD_PHOTO)); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); parameters.add(new Parameter("photoset_id", photosetId)); parameters.add(new Parameter("photo_id", photoId)); OAuthUtils.addOAuthToken(parameters); Response response = transportAPI.postJSON(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } }
Example #14
Source File: OAuthActivity.java From android-opensource-library-56 with Apache License 2.0 | 5 votes |
private void startOauth() { new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... params) { try { OAuthInterface oAuthInterface = mFlickr.getOAuthInterface(); mOAuthToken = oAuthInterface.getRequestToken(null); URL oauthUrl = oAuthInterface.buildAuthenticationUrl( Permission.WRITE, mOAuthToken); return oauthUrl.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String result) { if (result != null) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(result)); startActivity(intent); } } }.execute(); }
Example #15
Source File: OAuthActivity.java From android-opensource-library-56 with Apache License 2.0 | 5 votes |
private void verifyPin(String pin) { if (mOAuthToken == null) { return; } new AsyncTask<String, Void, Boolean>() { protected Boolean doInBackground(String[] params) { try { OAuthInterface oauthApi = mFlickr.getOAuthInterface(); OAuth oauth = oauthApi.getAccessToken( mOAuthToken.getOauthToken(), mOAuthToken.getOauthTokenSecret(), params[0]); saveOAuthToken(oauth.getUser().getUsername(), oauth .getUser().getId(), oauth.getToken() .getOauthToken(), oauth.getToken() .getOauthTokenSecret()); return true; } catch (Exception e) { e.printStackTrace(); } return false; }; @Override protected void onPostExecute(Boolean result) { if (result) { String userName = getUserName(); Toast.makeText(This(), "OAuth OK!:" + userName, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(This(), "OAuth Failed!", Toast.LENGTH_SHORT) .show(); } } }.execute(pin); }
Example #16
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 4 votes |
/** * Get a list of all photosets for the specified user. * * This method does not require authentication. But to get a Photoset into the list, that contains just private photos, the call needs to be authenticated. * * @param userId * The User id * @return The Photosets collection * @throws IOException * @throws FlickrException * @throws JSONException */ public Photosets getList(String userId) throws IOException, FlickrException, JSONException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_GET_LIST)); boolean signed = OAuthUtils.hasSigned(); if (signed) { parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); } else { parameters.add(new Parameter("api_key", apiKey)); } if (userId != null) { parameters.add(new Parameter("user_id", userId)); } if (signed) { OAuthUtils.addOAuthToken(parameters); } Response response = signed ? transportAPI.postJSON(sharedSecret, parameters) : transportAPI.get(transportAPI.getPath(), parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } Photosets photosetsObject = new Photosets(); JSONObject photosetsElement = response.getData().getJSONObject("photosets"); List<Photoset> photosets = new ArrayList<Photoset>(); JSONArray photosetElements = photosetsElement.optJSONArray("photoset"); for (int i = 0; photosetElements != null && i < photosetElements.length(); i++) { JSONObject photosetElement = photosetElements.getJSONObject(i); Photoset photoset = new Photoset(); photoset.setId(photosetElement.getString("id")); if (photosetElement.has("owner")) { User owner = new User(); owner.setId(photosetElement.getString("owner")); photoset.setOwner(owner); } Photo primaryPhoto = new Photo(); primaryPhoto.setId(photosetElement.getString("primary")); primaryPhoto.setSecret(photosetElement.getString("secret")); // TODO verify that this is the secret for the photo primaryPhoto.setServer(photosetElement.getString("server")); // TODO verify that this is the server for the photo primaryPhoto.setFarm(photosetElement.getString("farm")); photoset.setPrimaryPhoto(primaryPhoto); photoset.setSecret(photosetElement.getString("secret")); photoset.setServer(photosetElement.getString("server")); photoset.setFarm(photosetElement.getString("farm")); photoset.setPhotoCount(photosetElement.getString("photos")); photoset.setTitle(JSONUtils.getChildValue(photosetElement, "title")); photoset.setDescription(JSONUtils.getChildValue(photosetElement, "description")); photosets.add(photoset); } photosetsObject.setPhotosets(photosets); return photosetsObject; }
Example #17
Source File: PhotosetsInterface.java From flickr-uploader with GNU General Public License v2.0 | 4 votes |
/** * Get a collection of Photo objects for the specified Photoset. * * This method does not require authentication. * * @see com.gmail.yuyang226.flickr.photos.Extras * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_NO_FILTER * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_PUBLIC * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS_FAMILY * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FAMILY * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS * @param photosetId * The photoset ID * @param extras * Set of extra-fields * @param privacy_filter * filter value for authenticated calls * @param perPage * The number of photos per page * @param page * The page offset * @return PhotoList The Collection of Photo objects * @throws IOException * @throws FlickrException * @throws JSONException */ public PhotoList getPhotos(String photosetId, Set<String> extras, int privacy_filter, int perPage, int page) throws IOException, FlickrException, JSONException { PhotoList photos = new PhotoList(); List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter("method", METHOD_GET_PHOTOS)); boolean signed = OAuthUtils.hasSigned(); if (signed) { parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey)); } else { parameters.add(new Parameter("api_key", apiKey)); } parameters.add(new Parameter("photoset_id", photosetId)); if (perPage > 0) { parameters.add(new Parameter("per_page", Integer.valueOf(perPage))); } if (page > 0) { parameters.add(new Parameter("page", Integer.valueOf(page))); } if (privacy_filter > 0) { parameters.add(new Parameter("privacy_filter", "" + privacy_filter)); } if (extras != null && !extras.isEmpty()) { parameters.add(new Parameter(Extras.KEY_EXTRAS, StringUtilities.join(extras, ","))); } if (signed) { OAuthUtils.addOAuthToken(parameters); } Response response = signed ? transportAPI.postJSON(sharedSecret, parameters) : transportAPI.get(transportAPI.getPath(), parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } JSONObject photoset = response.getData().getJSONObject("photoset"); JSONArray photoElements = photoset.optJSONArray("photo"); photos.setPage(photoset.getString("page")); photos.setPages(photoset.getString("pages")); photos.setPerPage(photoset.getString("per_page")); photos.setTotal(photoset.getString("total")); for (int i = 0; photoElements != null && i < photoElements.length(); i++) { JSONObject photoElement = photoElements.getJSONObject(i); photos.add(PhotoUtils.createPhoto(photoElement)); } return photos; }
Example #18
Source File: Uploader.java From flickr-uploader with GNU General Public License v2.0 | 4 votes |
/** * Upload a photo from an InputStream. * * @param in * @param metaData * @return photoId for sync mode or ticketId for async mode * @throws IOException * @throws FlickrException * @throws SAXException */ public String upload(String imageName, File file, UploadMetaData metaData, Media media) throws IOException, FlickrException, SAXException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, this.apiKey)); String title = metaData.getTitle(); if (title != null) parameters.add(new Parameter("title", title)); String description = metaData.getDescription(); if (description != null) parameters.add(new Parameter("description", description)); Collection<String> tags = metaData.getTags(); if (tags != null) { parameters.add(new Parameter("tags", StringUtilities.join(tags, " "))); } parameters.add(new Parameter("is_public", metaData.isPublicFlag() ? "1" : "0")); parameters.add(new Parameter("is_family", metaData.isFamilyFlag() ? "1" : "0")); parameters.add(new Parameter("is_friend", metaData.isFriendFlag() ? "1" : "0")); parameters.add(new Parameter("async", metaData.isAsync() ? "1" : "0")); if (metaData.getSafetyLevel() != null) { parameters.add(new Parameter("safety_level", metaData.getSafetyLevel())); } if (metaData.getContentType() != null) { parameters.add(new Parameter("content_type", metaData.getContentType())); } parameters.add(new ImageParameter(imageName, file)); OAuthUtils.addOAuthToken(parameters); OAuthUtils.addOAuthParams(sharedSecret, Uploader.URL_UPLOAD, parameters); UploaderResponse response = (UploaderResponse) ((REST) transport).sendUpload(Uploader.UPLOAD_PATH, parameters, media); // UploaderResponse response = (UploaderResponse) ((REST) transport).upload(sharedSecret, parameters, progressListener); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } String id = ""; if (metaData.isAsync()) { id = response.getTicketId(); } else { id = response.getPhotoId(); } return id; }
Example #19
Source File: Uploader.java From flickr-uploader with GNU General Public License v2.0 | 4 votes |
/** * Upload a photo from a byte-array. * * @param data * The photo data as a byte array * @param metaData * The meta data * @return photoId for sync mode or ticketId for async mode * @throws FlickrException * @throws IOException * @throws SAXException */ @Deprecated public String upload(String imageName, byte[] data, UploadMetaData metaData) throws FlickrException, IOException, SAXException { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, this.apiKey)); String title = metaData.getTitle(); if (title != null) parameters.add(new Parameter("title", title)); String description = metaData.getDescription(); if (description != null) parameters.add(new Parameter("description", description)); Collection<String> tags = metaData.getTags(); if (tags != null) parameters.add(new Parameter("tags", StringUtilities.join(tags, " "))); parameters.add(new Parameter("is_public", metaData.isPublicFlag() ? "1" : "0")); parameters.add(new Parameter("is_family", metaData.isFamilyFlag() ? "1" : "0")); parameters.add(new Parameter("is_friend", metaData.isFriendFlag() ? "1" : "0")); parameters.add(new ImageParameter(imageName, data)); if (metaData.isHidden() != null) { parameters.add(new Parameter("hidden", metaData.isHidden().booleanValue() ? "1" : "0")); } if (metaData.getSafetyLevel() != null) { parameters.add(new Parameter("safety_level", metaData.getSafetyLevel())); } parameters.add(new Parameter("async", metaData.isAsync() ? "1" : "0")); if (metaData.getContentType() != null) { parameters.add(new Parameter("content_type", metaData.getContentType())); } OAuthUtils.addOAuthToken(parameters); UploaderResponse response = (UploaderResponse) transport.upload(sharedSecret, parameters); if (response.isError()) { throw new FlickrException(response.getErrorCode(), response.getErrorMessage()); } String id = ""; if (metaData.isAsync()) { id = response.getTicketId(); } else { id = response.getPhotoId(); } return id; }