/** * Creates a new Request configured to upload an image to create a staging resource. Staging * resources allow you to post binary data such as images, in preparation for a post of an Open * Graph object or action which references the image. The URI returned when uploading a staging * resource may be passed as the image property for an Open Graph object or action. * * @param accessToken the access token to use, or null * @param file the file containing the image to upload * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws FileNotFoundException */ public static GraphRequest newUploadStagingResourceWithImageRequest( AccessToken accessToken, File file, Callback callback ) throws FileNotFoundException { ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); GraphRequest.ParcelableResourceWithMimeType<ParcelFileDescriptor> resourceWithMimeType = new GraphRequest.ParcelableResourceWithMimeType<>(descriptor, "image/png"); Bundle parameters = new Bundle(1); parameters.putParcelable(STAGING_PARAM, resourceWithMimeType); return new GraphRequest( accessToken, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback); }
private void shareLinkContent(final ShareLinkContent linkContent, final FacebookCallback<Sharer.Result> callback) { final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { final JSONObject data = response.getJSONObject(); final String postId = (data == null ? null : data.optString("id")); ShareInternalUtility.invokeCallbackWithResults(callback, postId, response); } }; final Bundle parameters = new Bundle(); this.addCommonParameters(parameters, linkContent); parameters.putString("message", this.getMessage()); parameters.putString("link", Utility.getUriString(linkContent.getContentUrl())); parameters.putString("picture", Utility.getUriString(linkContent.getImageUrl())); parameters.putString("name", linkContent.getContentTitle()); parameters.putString("description", linkContent.getContentDescription()); parameters.putString("ref", linkContent.getRef()); new GraphRequest( AccessToken.getCurrentAccessToken(), getGraphPath("feed"), parameters, HttpMethod.POST, requestCallback).executeAsync(); }
public void getPermissions() { String uri = "me/permissions/"; new GraphRequest(AccessToken.getCurrentAccessToken(), uri, null, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { /* handle the result */ JSONArray data = response.getJSONObject().optJSONArray("data"); mUserPermissions.clear(); for (int i = 0; i < data.length(); i++) { JSONObject dd = data.optJSONObject(i); if (dd.optString("status").equals("granted")) { mUserPermissions .add(dd.optString("permission")); } } } } ).executeAsync(); }
protected void doFacebookCall(Activity parent, Map<String, Object> postData, String graphPath, HttpMethod method, SocialNetworkPostListener listener) { Bundle bundle = new Bundle(); if(postData != null) { Set<Entry<String, Object>> entries = postData.entrySet(); for (Entry<String, Object> entry : entries) { Object value = entry.getValue(); if(value instanceof byte[]) { bundle.putByteArray(entry.getKey(), (byte[]) value); } else { bundle.putString(entry.getKey(), value.toString()); } } } doFacebookCall(parent, bundle, graphPath, method, listener); }
private void createAppLinkIfNeeded() { if (mPlace != null && mAppLink == null && Utils.isConnected(getContext())) { String token = getContext().getString(R.string.facebook_app_id) + "|" + getContext().getString(R.string.facebook_app_secret); Bundle parameters = new Bundle(); parameters.putString("name", "Sjekk Ut"); parameters.putString("access_token", token); parameters.putString("web", "{\"should_fallback\": false}"); parameters.putString("iphone", "[{\"url\": \"sjekkut://place/" + mPlace.getId() + "\"}]"); parameters.putString("android", "[{\"url\": \"no.dnt.sjekkut://place/" + mPlace.getId() + "\", \"package\": \"no.dnt.sjekkut\"}]"); new GraphRequest( null, "/app/app_link_hosts", parameters, HttpMethod.POST, this).executeAsync(); } }
@Override public List<String> getThirdPartyFriendIds() throws SocialNetworkException { if (!isAuthorizedToSocialNetwork()) { throw new NotAuthorizedToSocialNetworkException(); } GraphResponse response = new GraphRequest( facebookTokenHolder.getToken(), FACEBOOK_FRIENDS_GRAPH_PATH, Bundle.EMPTY, HttpMethod.GET ).executeAndWait(); facebookTokenHolder.clearToken(); FacebookRequestError responseError = response.getError(); if (responseError != null) { throw new SocialNetworkException("Internal facebook failure: " + responseError.getErrorMessage() + " [" + responseError.getErrorCode() + "]"); } return extractFacebookFriendIds(response); }
public void setPhoto(final ImageView imageView, final Button button){ new GraphRequest( AccessToken.getCurrentAccessToken(), "me?fields=picture.width(500).height(500)", null, HttpMethod.GET, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { try { Log.d("LOG onComplete", String.valueOf(AccessToken.getCurrentAccessToken())); String url=new FacebookJsonParse().FacebookImageParse(response.getJSONObject()); imageView.setVisibility(View.VISIBLE); button.setVisibility(View.GONE); Glide.with(context).load(url).into(imageView); } catch (JSONException e) { Log.d("FacebookSdkHelper",e.getMessage()); } } } ).executeAsync(); }
protected void execute() { if (sessionManager.isLoggedIn()) { AccessToken accessToken = sessionManager.getAccessToken(); Bundle bundle = updateAppSecretProof(); GraphRequest request = new GraphRequest(accessToken, getGraphPath(), bundle, HttpMethod.GET); request.setVersion(configuration.getGraphVersion()); runRequest(request); } else { String reason = Errors.getError(Errors.ErrorMsg.LOGIN); Logger.logError(getClass(), reason, null); if (mSingleEmitter != null) { mSingleEmitter.onError(new FacebookAuthorizationException(reason)); } } }
private void getFacebookInfo() { Bundle parameters = new Bundle(); parameters.putString("fields", "picture, first_name, id"); new GraphRequest(AccessToken.getCurrentAccessToken(), "/me", parameters, HttpMethod.GET, new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse graphResponse) { JSONObject user = graphResponse.getJSONObject(); ParseUser currentUser = ParseUser.getCurrentUser(); currentUser.put("firstName", user.optString("first_name")); currentUser.put("facebookId", user.optString("id")); currentUser.put("pictureURL", user.optJSONObject("picture").optJSONObject("data").optString("url")); currentUser.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e == null) { Log.i(TAG, "User saved"); setResult(RESULT_OK); finish(); } } }); } }).executeAsync(); }
/** * Creates a new Request configured to create a user owned Open Graph object. * * @param accessToken the accessToken to use, or null * @param openGraphObject the Open Graph object to create; must not be null, and must have a * non-empty type and title * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ public static GraphRequest newPostOpenGraphObjectRequest( AccessToken accessToken, JSONObject openGraphObject, Callback callback) { if (openGraphObject == null) { throw new FacebookException("openGraphObject cannot be null"); } if (Utility.isNullOrEmpty(openGraphObject.optString("type"))) { throw new FacebookException("openGraphObject must have non-null 'type' property"); } if (Utility.isNullOrEmpty(openGraphObject.optString("title"))) { throw new FacebookException("openGraphObject must have non-null 'title' property"); } String path = String.format(MY_OBJECTS_FORMAT, openGraphObject.optString("type")); Bundle bundle = new Bundle(); bundle.putString(OBJECT_PARAM, openGraphObject.toString()); return new GraphRequest(accessToken, path, bundle, HttpMethod.POST, callback); }
/** * Creates a new Request configured to update a user owned Open Graph object. * * @param accessToken the access token to use, or null * @param openGraphObject the Open Graph object to update, which must have a valid 'id' * property * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ public static GraphRequest newUpdateOpenGraphObjectRequest( AccessToken accessToken, JSONObject openGraphObject, Callback callback) { if (openGraphObject == null) { throw new FacebookException("openGraphObject cannot be null"); } String path = openGraphObject.optString("id"); if (path == null) { throw new FacebookException("openGraphObject must have an id"); } Bundle bundle = new Bundle(); bundle.putString(OBJECT_PARAM, openGraphObject.toString()); return new GraphRequest(accessToken, path, bundle, HttpMethod.POST, callback); }
/** * Creates a new Request configured to upload a photo to the user's default photo album. The * photo will be read from the specified Uri. * @param accessToken the access token to use, or null * @param photoUri the file:// or content:// Uri to the photo on device. * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws FileNotFoundException */ public static GraphRequest newUploadPhotoRequest( AccessToken accessToken, Uri photoUri, Callback callback) throws FileNotFoundException { if (Utility.isFileUri(photoUri)) { return newUploadPhotoRequest(accessToken, new File(photoUri.getPath()), callback); } else if (!Utility.isContentUri(photoUri)) { throw new FacebookException("The photo Uri must be either a file:// or content:// Uri"); } Bundle parameters = new Bundle(1); parameters.putParcelable(PICTURE_PARAM, photoUri); return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback); }
/** * Creates a new Request configured to upload a photo to the user's default photo album. The * photo will be read from the specified Uri. * @param accessToken the access token to use, or null * @param videoUri the file:// or content:// Uri to the video on device. * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws FileNotFoundException */ public static GraphRequest newUploadVideoRequest( AccessToken accessToken, Uri videoUri, Callback callback) throws FileNotFoundException { if (Utility.isFileUri(videoUri)) { return newUploadVideoRequest(accessToken, new File(videoUri.getPath()), callback); } else if (!Utility.isContentUri(videoUri)) { throw new FacebookException("The video Uri must be either a file:// or content:// Uri"); } Bundle parameters = new Bundle(1); parameters.putParcelable(PICTURE_PARAM, videoUri); return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback); }
/** * Creates a new Request configured to post a status update to a user's feed. * * @param accessToken the access token to use, or null * @param message the text of the status update * @param placeId an optional place id to associate with the post * @param tagIds an optional list of user ids to tag in the post * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ private static GraphRequest newStatusUpdateRequest( AccessToken accessToken, String message, String placeId, List<String> tagIds, Callback callback) { Bundle parameters = new Bundle(); parameters.putString("message", message); if (placeId != null) { parameters.putString("place", placeId); } if (tagIds != null && tagIds.size() > 0) { String tags = TextUtils.join(",", tagIds); parameters.putString("tags", tags); } return new GraphRequest(accessToken, MY_FEED, parameters, HttpMethod.POST, callback); }
private void shareLinkContent(final ShareLinkContent linkContent, final FacebookCallback<Sharer.Result> callback) { final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { final JSONObject data = response.getJSONObject(); final String postId = (data == null ? null : data.optString("id")); ShareInternalUtility.invokeCallbackWithResults(callback, postId, response); } }; final Bundle parameters = new Bundle(); parameters.putString("link", Utility.getUriString(linkContent.getContentUrl())); parameters.putString("picture", Utility.getUriString(linkContent.getImageUrl())); parameters.putString("name", linkContent.getContentTitle()); parameters.putString("description", linkContent.getContentDescription()); parameters.putString("ref", linkContent.getRef()); new GraphRequest( AccessToken.getCurrentAccessToken(), "/me/feed", parameters, HttpMethod.POST, requestCallback).executeAsync(); }
/** * Changes the UI when an interaction with the Session object occurs with the user. * @param session The current active Session. * @param sessionState The current state of the active Session. * @param e An Exception if there is one. */ private void onSessionStateChange(Session session, SessionState sessionState, Exception e) { if (sessionState == SessionState.OPENED) { Log.d(TAG, "Successful login!"); new Request(session, "/me", null, HttpMethod.GET, new Request.Callback() { @Override public void onCompleted(Response response) { JSONObject obj = response.getGraphObject().getInnerJSONObject(); Log.d(TAG, "Got back " + obj + " from Facebook API."); UserSession.getInstance().setFacebookData(obj); getUserData(); } }).executeAsync(); } else if (e != null) { // handle exception } }
public void populateContact() { final Session session = Session.getActiveSession(); new Request(session, "/me/friends", null, HttpMethod.GET, new Request.Callback() { public void onCompleted(Response response) { // Process the returned response GraphObject graphObject = response.getGraphObject(); if (graphObject != null) { // Check if there is extra data if (graphObject.getProperty("data") != null) { JSONArray arrayObject = (JSONArray) graphObject .getProperty("data"); int count = arrayObject.length(); if(count == 0) hasAppFriends = false; // Ensure the user has at least one friend //session.close(); } } } }).executeAsync(); }
public void requestFacebookCoverPhoto(AccessToken accessToken, final FacebookGetLoginUserCallback callback) { if (NetworkUtils.getInstance().isOnline()) { Bundle params = new Bundle(); params.putString("fields", "cover"); GraphRequest request = new GraphRequest( accessToken, "me", params, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { try { JSONObject coverResponse = response.getJSONObject().getJSONObject("cover"); String coverUrl = coverResponse.getString("source"); UserModel.getInstance().addFacebookCoverUrl(coverUrl); callback.onSuccess(); } catch (JSONException e) { e.printStackTrace(); } } } ); request.executeAsync(); } }
public void requestFacebookProfilePhoto(AccessToken accessToken, final FacebookGetLoginUserCallback callback) { if (NetworkUtils.getInstance().isOnline()) { Bundle params = new Bundle(); params.putString("redirect", "false"); params.putString("type", "large"); GraphRequest request = new GraphRequest( accessToken, "me/picture", params, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { try { String profilePhotoUrl = response.getJSONObject().getJSONObject("data").getString("url"); UserModel.getInstance().addFacebookProfileUrl(profilePhotoUrl); callback.onSuccess(); } catch (JSONException e) { e.printStackTrace(); } } } ); request.executeAsync(); } }
/** * Creates a new Request configured to upload a photo to the user's default photo album. The * photo will be read from the specified file. * * @param accessToken the access token to use, or null * @param file the file containing the photo to upload * @param caption the user generated caption for the photo. * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws java.io.FileNotFoundException */ public static GraphRequest newUploadPhotoRequest( AccessToken accessToken, File file, String caption, Callback callback ) throws FileNotFoundException { ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); Bundle parameters = new Bundle(1); parameters.putParcelable(PICTURE_PARAM, descriptor); if (caption != null && !caption.isEmpty()) { parameters.putString(CAPTION_PARAM, caption); } return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback); }
/** * Creates a new Request configured to upload a photo to the user's default photo album. The * photo will be read from the specified Uri. * * @param accessToken the access token to use, or null * @param photoUri the file:// or content:// Uri to the photo on device. * @param caption the user generated caption for the photo. * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws FileNotFoundException */ public static GraphRequest newUploadPhotoRequest( AccessToken accessToken, Uri photoUri, String caption, Callback callback) throws FileNotFoundException { if (Utility.isFileUri(photoUri)) { return newUploadPhotoRequest( accessToken, new File(photoUri.getPath()), caption, callback); } else if (!Utility.isContentUri(photoUri)) { throw new FacebookException("The photo Uri must be either a file:// or content:// Uri"); } Bundle parameters = new Bundle(1); parameters.putParcelable(PICTURE_PARAM, photoUri); return new GraphRequest(accessToken, MY_PHOTOS, parameters, HttpMethod.POST, callback); }
private void shareLinkContent(final ShareLinkContent linkContent, final FacebookCallback<Sharer.Result> callback) { final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { final JSONObject data = response.getJSONObject(); final String postId = (data == null ? null : data.optString("id")); ShareInternalUtility.invokeCallbackWithResults(callback, postId, response); } }; final Bundle parameters = new Bundle(); this.addCommonParameters(parameters, linkContent); parameters.putString("message", this.getMessage()); parameters.putString("link", Utility.getUriString(linkContent.getContentUrl())); parameters.putString("picture", Utility.getUriString(linkContent.getImageUrl())); parameters.putString("name", linkContent.getContentTitle()); parameters.putString("description", linkContent.getContentDescription()); parameters.putString("ref", linkContent.getRef()); new GraphRequest( AccessToken.getCurrentAccessToken(), "/me/feed", parameters, HttpMethod.POST, requestCallback).executeAsync(); }
public void getPhotos(){ new Request( ParseFacebookUtils.getSession(), "/me/photos", null, HttpMethod.GET, new Request.Callback() { public void onCompleted(Response response) { GraphObject obj = response.getGraphObject(); JSONArray array =(JSONArray) obj.getProperty("data"); //Only save valid photo array if(array != null && array.length() > 0) { ParseUser.getCurrentUser().put(Enums.ParseKey.USER_FB_PHOTOS, array.toString()); ParseUser.getCurrentUser().saveInBackground(); } } } ).executeAsync(); }
/** * Asynchronously requests the Page accounts associated with the linked account. Requires an opened active {@link Session}. * * @param callback a {@link Callback} when the request completes. * @return true if the request is made; false if no opened {@link Session} is active. */ boolean requestAccounts(Callback callback) { boolean isSuccessful = false; Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { // Construct fields to request. Bundle params = new Bundle(); params.putString(ACCOUNTS_LISTING_FEILDS_KEY, ACCOUNTS_LISTING_FIELDS_VALUE); // Construct and execute albums listing request. Request request = new Request(session, ACCOUNTS_LISTING_GRAPH_PATH, params, HttpMethod.GET, callback); request.executeAsync(); isSuccessful = true; } return isSuccessful; }
/** * Asynchronously requests the albums associated with the linked account. Requires an opened active {@link Session}. * * @param id may be {@link #ME} or a Page id. * @param callback a {@link Callback} when the request completes. * @return true if the request is made; false if no opened {@link Session} is active. */ boolean requestAlbums(String id, Callback callback) { boolean isSuccessful = false; Session session = Session.getActiveSession(); if (session != null && session.isOpened()) { // Construct fields to request. Bundle params = new Bundle(); params.putString(ALBUMS_LISTING_LIMIT_KEY, ALBUMS_LISTING_LIMIT_VALUE); params.putString(ALBUMS_LISTING_FEILDS_KEY, ALBUMS_LISTING_FIELDS_VALUE); // Construct and execute albums listing request. Request request = new Request(session, id + TO_ALBUMS_LISTING_GRAPH_PATH, params, HttpMethod.GET, callback); request.executeAsync(); isSuccessful = true; } return isSuccessful; }
private void createAlbum() { // TODO Auto-generated method stub Bundle params = new Bundle(); params.putString("name", ViewStory.this.story.getName()); params.putString("message", ViewStory.this.story.getComment()); Request request = new Request(MainActivity.session, "me/albums", params, HttpMethod.POST); request.setCallback(new Request.Callback() { @Override public void onCompleted(Response response) { // TODO Auto-generated method stub try { jo = response.getGraphObject().getInnerJSONObject().getJSONArray("data").getJSONObject(0); Toast.makeText(ViewStory.this, "ALBUM CREATION COMPLETED\n", Toast.LENGTH_LONG).show(); uploadImagesToAlbum(jo); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(ViewStory.this, "ALBUM CREATION FAILED\n", Toast.LENGTH_LONG).show(); } } }); request.executeAsync(); }
private void uploadImagesToAlbum(JSONObject jo) throws JSONException { // TODO Auto-generated method stub ArrayList<Photo> photos = db.get_photos(ViewStory.this.story.getId()); for (int i = 0; i < photos.size(); i++) { String imgUrl = photos.get(i).getUrl(); Bitmap bmp = BitmapFactory.decodeFile(imgUrl); String imgComment = photos.get(i).getComment(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); Bundle params = new Bundle(); params.putByteArray("source", byteArray); params.putString("message", imgComment); Request rr = new Request(MainActivity.session, jo.getString("id")+"/photos", params, HttpMethod.POST); rr.setCallback(new Callback() { @Override public void onCompleted(Response response) { // TODO Auto-generated method stub Toast.makeText(ViewStory.this, "PHOTO ADDED SUCESSFULLY", Toast.LENGTH_LONG).show(); } }); rr.executeAsync(); } }
private Session startSession() { // TODO Auto-generated method stub return Session.openActiveSession(ViewStory.this, true, new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { Toast.makeText(ViewStory.this, "STEP 1: "+session.getAccessToken()+"\n"+session.getState(), Toast.LENGTH_LONG).show(); // TODO Auto-generated method stub if (session.isOpened()){ Toast.makeText(ViewStory.this, "OPENED: "+session.getAccessToken()+"\n"+session.getApplicationId(), Toast.LENGTH_LONG).show(); Request request = new Request(MainActivity.session, "me/albums", null, HttpMethod.GET, getAlbums); request.executeAsync(); } } }); }
/** * Creates a new Request configured to upload an image to create a staging resource. Staging * resources allow you to post binary data such as images, in preparation for a post of an Open * Graph object or action which references the image. The URI returned when uploading a staging * resource may be passed as the image property for an Open Graph object or action. * * @param accessToken the access token to use, or null * @param image the image to upload * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute */ public static GraphRequest newUploadStagingResourceWithImageRequest( AccessToken accessToken, Bitmap image, Callback callback) { Bundle parameters = new Bundle(1); parameters.putParcelable(STAGING_PARAM, image); return new GraphRequest( accessToken, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback); }
/** * Creates a new Request configured to upload an image to create a staging resource. Staging * resources allow you to post binary data such as images, in preparation for a post of an Open * Graph object or action which references the image. The URI returned when uploading a staging * resource may be passed as the image property for an Open Graph object or action. * * @param accessToken the access token to use, or null * @param imageUri the file:// or content:// Uri pointing to the image to upload * @param callback a callback that will be called when the request is completed to handle * success or error conditions * @return a Request that is ready to execute * @throws FileNotFoundException */ public static GraphRequest newUploadStagingResourceWithImageRequest( AccessToken accessToken, Uri imageUri, Callback callback ) throws FileNotFoundException { if (Utility.isFileUri(imageUri)) { return newUploadStagingResourceWithImageRequest( accessToken, new File(imageUri.getPath()), callback); } else if (!Utility.isContentUri(imageUri)) { throw new FacebookException("The image Uri must be either a file:// or content:// Uri"); } GraphRequest.ParcelableResourceWithMimeType<Uri> resourceWithMimeType = new GraphRequest.ParcelableResourceWithMimeType<>(imageUri, "image/png"); Bundle parameters = new Bundle(1); parameters.putParcelable(STAGING_PARAM, resourceWithMimeType); return new GraphRequest( accessToken, MY_STAGING_RESOURCES, parameters, HttpMethod.POST, callback); }
protected void executeGraphRequestSynchronously(Bundle parameters) { GraphRequest request = new GraphRequest( uploadContext.accessToken, String.format(Locale.ROOT, "%s/videos", uploadContext.graphNode), parameters, HttpMethod.POST, null); GraphResponse response = request.executeAndWait(); if (response != null) { FacebookRequestError error = response.getError(); JSONObject responseJSON = response.getJSONObject(); if (error != null) { if (!attemptRetry(error.getSubErrorCode())) { handleError(new FacebookGraphResponseException(response, ERROR_UPLOAD)); } } else if (responseJSON != null) { try { handleSuccess(responseJSON); } catch (JSONException e) { endUploadWithFailure(new FacebookException(ERROR_BAD_SERVER_RESPONSE, e)); } } else { handleError(new FacebookException(ERROR_BAD_SERVER_RESPONSE)); } } else { handleError(new FacebookException(ERROR_BAD_SERVER_RESPONSE)); } }
private static GraphRequest getGraphMeRequestWithCache( final String accessToken) { Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,first_name,middle_name,last_name,link"); parameters.putString("access_token", accessToken); GraphRequest graphRequest = new GraphRequest( null, "me", parameters, HttpMethod.GET, null); return graphRequest; }
public void logout() { if (AccessToken.getCurrentAccessToken() == null) { return; // already logged out } new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest .Callback() { @Override public void onCompleted(GraphResponse graphResponse) { LoginManager.getInstance().logOut(); } }).executeAsync(); }
private void publishStory(final String message) { if (AccessToken.getCurrentAccessToken() != null) { Bundle postParams = new Bundle(); postParams.putString("message", message); GraphRequest.Callback callback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse graphResponse) { FacebookRequestError error = graphResponse.getError(); if (error != null) { if (eventHandler != null) { Log.sysOut("$#$#$ " + error); eventHandler.stopProgress(); eventHandler.onFacebookError(error .getErrorMessage()); } return; } if (eventHandler != null) { eventHandler.stopProgress(); eventHandler.onRecievePost(message); } } }; GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), "feed", postParams, HttpMethod.POST, callback); request.executeAsync(); } else if (eventHandler != null) eventHandler.onFacebookError(activity.getString(R.string.facebook_you_must_login_first_toast)); }