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(); }
@Override protected void registerCallbackImpl ( final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) { final ResultProcessor resultProcessor = (callback == null) ? null : new ResultProcessor(callback) { @Override public void onSuccess(AppCall appCall, Bundle results) { callback.onSuccess(new Result(results)); } }; CallbackManagerImpl.Callback callbackManagerCallback = new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { return ShareInternalUtility.handleActivityResult( getRequestCode(), resultCode, data, resultProcessor); } }; callbackManager.registerCallback(getRequestCode(), callbackManagerCallback); }
@Override protected void registerCallbackImpl( final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) { final ResultProcessor resultProcessor = (callback == null) ? null : new ResultProcessor(callback) { @Override public void onSuccess(AppCall appCall, Bundle results) { callback.onSuccess(new Result(results.getString("id"))); } }; CallbackManagerImpl.Callback callbackManagerCallback = new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { return ShareInternalUtility.handleActivityResult( getRequestCode(), resultCode, data, resultProcessor); } }; callbackManager.registerCallback(getRequestCode(), callbackManagerCallback); }
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(); }
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(); }
/** * Share the content. * * @param callback the callback to call once the share is complete. */ public void share(FacebookCallback<Sharer.Result> callback) { if (!this.canShare()) { ShareInternalUtility.invokeCallbackWithError( callback, "Insufficient permissions for sharing content via Api."); return; } final ShareContent shareContent = this.getShareContent(); // Validate the share content try { ShareContentValidation.validateForApiShare(shareContent); } catch (FacebookException ex) { ShareInternalUtility.invokeCallbackWithException(callback, ex); return; } if (shareContent instanceof ShareLinkContent) { this.shareLinkContent((ShareLinkContent) shareContent, callback); } else if (shareContent instanceof SharePhotoContent) { this.sharePhotoContent((SharePhotoContent) shareContent, callback); } else if (shareContent instanceof ShareVideoContent) { this.shareVideoContent((ShareVideoContent) shareContent, callback); } else if (shareContent instanceof ShareOpenGraphContent) { this.shareOpenGraphContent((ShareOpenGraphContent) shareContent, callback); } }
private void shareVideoContent(final ShareVideoContent videoContent, final FacebookCallback<Sharer.Result> callback) { try { VideoUploader.uploadAsync(videoContent, getGraphNode(), callback); } catch (final FileNotFoundException ex) { ShareInternalUtility.invokeCallbackWithException(callback, ex); } }
@Override protected void registerCallbackImpl( final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) { ShareInternalUtility.registerSharerCallback( getRequestCode(), callbackManager, callback); }
@Override protected void registerCallbackImpl( final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) { final ResultProcessor resultProcessor = (callback == null) ? null : new ResultProcessor(callback) { @Override public void onSuccess(AppCall appCall, Bundle results) { if (results != null) { callback.onSuccess(new Result(results)); } else { onCancel(appCall); } } }; callbackManager.registerCallback( getRequestCode(), new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { return ShareInternalUtility.handleActivityResult( getRequestCode(), resultCode, data, resultProcessor); } }); }
private void shareVideoContent(final ShareVideoContent videoContent, final FacebookCallback<Sharer.Result> callback) { final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { String postId = null; if (response != null) { JSONObject responseJSON = response.getJSONObject(); if (responseJSON != null) { postId = responseJSON.optString("id"); } } ShareInternalUtility.invokeCallbackWithResults(callback, postId, response); } }; GraphRequest videoRequest; try { videoRequest = ShareInternalUtility.newUploadVideoRequest( AccessToken.getCurrentAccessToken(), videoContent.getVideo().getLocalUrl(), requestCallback); } catch (final FileNotFoundException ex) { ShareInternalUtility.invokeCallbackWithException(callback, ex); return; } final Bundle parameters = videoRequest.getParameters(); parameters.putString("title", videoContent.getContentTitle()); parameters.putString("description", videoContent.getContentDescription()); parameters.putString("ref", videoContent.getRef()); videoRequest.setParameters(parameters); videoRequest.executeAsync(); }
@Override protected void registerCallbackImpl( final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) { final ResultProcessor resultProcessor = (callback == null) ? null : new ResultProcessor(callback) { @Override public void onSuccess(AppCall appCall, Bundle results) { if (results != null) { callback.onSuccess(new Result(results.getString( ShareConstants.WEB_DIALOG_RESULT_PARAM_REQUEST_ID))); } else { onCancel(appCall); } } }; callbackManager.registerCallback( getRequestCode(), new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { return ShareInternalUtility.handleActivityResult( getRequestCode(), resultCode, data, resultProcessor); } }); }
private void shareVideoContent(final ShareVideoContent videoContent, final FacebookCallback<Sharer.Result> callback) { try { VideoUploader.uploadAsync(videoContent, callback); } catch (final FileNotFoundException ex) { ShareInternalUtility.invokeCallbackWithException(callback, ex); } }
private void shareOpenGraphContent(final ShareOpenGraphContent openGraphContent, final FacebookCallback<Sharer.Result> callback) { // In order to create a new Open Graph action using a custom object that does not already // exist (objectID or URL), you must first send a request to post the object and then // another to post the action. If a local image is supplied with the object or action, that // must be staged first and then referenced by the staging URL that is returned by that // request. 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 ShareOpenGraphAction action = openGraphContent.getAction(); final Bundle parameters = action.getBundle(); this.addCommonParameters(parameters, openGraphContent); if (!Utility.isNullOrEmpty(this.getMessage())) { parameters.putString("message", this.getMessage()); } final CollectionMapper.OnMapperCompleteListener stageCallback = new CollectionMapper .OnMapperCompleteListener() { @Override public void onComplete() { try { handleImagesOnAction(parameters); new GraphRequest( AccessToken.getCurrentAccessToken(), getGraphPath( URLEncoder.encode(action.getActionType(), DEFAULT_CHARSET)), parameters, HttpMethod.POST, requestCallback).executeAsync(); } catch (final UnsupportedEncodingException ex) { ShareInternalUtility.invokeCallbackWithException(callback, ex); } } @Override public void onError(FacebookException exception) { ShareInternalUtility.invokeCallbackWithException(callback, exception); } }; this.stageOpenGraphAction(parameters, stageCallback); }
private void sharePhotoContent(final SharePhotoContent photoContent, final FacebookCallback<Sharer.Result> callback) { final Mutable<Integer> requestCount = new Mutable<Integer>(0); final AccessToken accessToken = AccessToken.getCurrentAccessToken(); final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>(); final ArrayList<JSONObject> results = new ArrayList<JSONObject>(); final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>(); final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { final JSONObject result = response.getJSONObject(); if (result != null) { results.add(result); } if (response.getError() != null) { errorResponses.add(response); } requestCount.value -= 1; if (requestCount.value == 0) { if (!errorResponses.isEmpty()) { ShareInternalUtility.invokeCallbackWithResults( callback, null, errorResponses.get(0)); } else if (!results.isEmpty()) { final String postId = results.get(0).optString("id"); ShareInternalUtility.invokeCallbackWithResults( callback, postId, response); } } } }; try { for (SharePhoto photo : photoContent.getPhotos()) { final Bitmap bitmap = photo.getBitmap(); final Uri photoUri = photo.getImageUrl(); String caption = photo.getCaption(); if (caption == null) { caption = this.getMessage(); } if (bitmap != null) { requests.add(GraphRequest.newUploadPhotoRequest( accessToken, getGraphPath(PHOTOS_EDGE), bitmap, caption, photo.getParameters(), requestCallback)); } else if (photoUri != null) { requests.add(GraphRequest.newUploadPhotoRequest( accessToken, getGraphPath(PHOTOS_EDGE), photoUri, caption, photo.getParameters(), requestCallback)); } } requestCount.value += requests.size(); for (GraphRequest request : requests) { request.executeAsync(); } } catch (final FileNotFoundException ex) { ShareInternalUtility.invokeCallbackWithException(callback, ex); } }
/** * Constructs a MessageDialog. * @param activity Activity to use to send the provided content. */ public MessageDialog(Activity activity) { super(activity, DEFAULT_REQUEST_CODE); ShareInternalUtility.registerStaticShareCallback(DEFAULT_REQUEST_CODE); }
/** * Constructs a MessageDialog. * @param fragment Fragment to use to send the provided content. */ public MessageDialog(Fragment fragment) { super(fragment, DEFAULT_REQUEST_CODE); ShareInternalUtility.registerStaticShareCallback(DEFAULT_REQUEST_CODE); }
MessageDialog(Activity activity, int requestCode) { super(activity, requestCode); ShareInternalUtility.registerStaticShareCallback(requestCode); }
MessageDialog(Fragment fragment, int requestCode) { super(fragment, requestCode); ShareInternalUtility.registerStaticShareCallback(requestCode); }
@Override protected void registerCallbackImpl( final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) { ShareInternalUtility.registerSharerCallback(getRequestCode(), callbackManager, callback); }
/** * Constructs a new ShareDialog. * @param activity Activity to use to share the provided content. */ public ShareDialog(Activity activity) { super(activity, DEFAULT_REQUEST_CODE); ShareInternalUtility.registerStaticShareCallback(DEFAULT_REQUEST_CODE); }
/** * Constructs a new ShareDialog. * @param fragment Fragment to use to share the provided content. */ public ShareDialog(Fragment fragment) { super(fragment, DEFAULT_REQUEST_CODE); ShareInternalUtility.registerStaticShareCallback(DEFAULT_REQUEST_CODE); }
ShareDialog(Activity activity, int requestCode) { super(activity, requestCode); ShareInternalUtility.registerStaticShareCallback(requestCode); }
ShareDialog(Fragment fragment, int requestCode) { super(fragment, requestCode); ShareInternalUtility.registerStaticShareCallback(requestCode); }
private void shareOpenGraphContent(final ShareOpenGraphContent openGraphContent, final FacebookCallback<Sharer.Result> callback) { // In order to create a new Open Graph action using a custom object that does not already // exist (objectID or URL), you must first send a request to post the object and then // another to post the action. If a local image is supplied with the object or action, that // must be staged first and then referenced by the staging URL that is returned by that // request. 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 ShareOpenGraphAction action = openGraphContent.getAction(); final Bundle parameters = action.getBundle(); final CollectionMapper.OnMapperCompleteListener stageCallback = new CollectionMapper .OnMapperCompleteListener() { @Override public void onComplete() { try { handleImagesOnAction(parameters); new GraphRequest( AccessToken.getCurrentAccessToken(), "/me/" + URLEncoder.encode(action.getActionType(), "UTF-8"), parameters, HttpMethod.POST, requestCallback).executeAsync(); } catch (final UnsupportedEncodingException ex) { ShareInternalUtility.invokeCallbackWithException(callback, ex); } } @Override public void onError(FacebookException exception) { ShareInternalUtility.invokeCallbackWithException(callback, exception); } }; this.stageOpenGraphAction(parameters, stageCallback); }
private void sharePhotoContent(final SharePhotoContent photoContent, final FacebookCallback<Sharer.Result> callback) { final Mutable<Integer> requestCount = new Mutable<Integer>(0); final AccessToken accessToken = AccessToken.getCurrentAccessToken(); final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>(); final ArrayList<JSONObject> results = new ArrayList<JSONObject>(); final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>(); final GraphRequest.Callback requestCallback = new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { final JSONObject result = response.getJSONObject(); if (result != null) { results.add(result); } if (response.getError() != null) { errorResponses.add(response); } requestCount.value -= 1; if (requestCount.value == 0) { if (!errorResponses.isEmpty()) { ShareInternalUtility.invokeCallbackWithResults( callback, null, errorResponses.get(0)); } else if (!results.isEmpty()) { final String postId = results.get(0).optString("id"); ShareInternalUtility.invokeCallbackWithResults( callback, postId, response); } } } }; try { for (SharePhoto photo : photoContent.getPhotos()) { final Bitmap bitmap = photo.getBitmap(); final Uri photoUri = photo.getImageUrl(); if (bitmap != null) { requests.add(ShareInternalUtility.newUploadPhotoRequest( accessToken, bitmap, requestCallback)); } else if (photoUri != null) { requests.add(ShareInternalUtility.newUploadPhotoRequest( accessToken, photoUri, requestCallback)); } } requestCount.value += requests.size(); for (GraphRequest request : requests) { request.executeAsync(); } } catch (final FileNotFoundException ex) { ShareInternalUtility.invokeCallbackWithException(callback, ex); } }