@Override public void onSuccess(AppCall appCall, Bundle results) { if (results != null) { final String gesture = getNativeDialogCompletionGesture(results); if (gesture == null || "post".equalsIgnoreCase(gesture)) { String postId = getShareDialogPostId(results); invokeOnSuccessCallback(callback, postId); } else if ("cancel".equalsIgnoreCase(gesture)) { invokeOnCancelCallback(callback); } else { invokeOnErrorCallback( callback, new FacebookException(NativeProtocol.ERROR_UNKNOWN_ERROR)); } } }
@Override public boolean onActivityResult(int resultCode, Intent data) { return handleActivityResult( requestCode, resultCode, data, getShareResultProcessor(null)); } }
public static void invokeCallbackWithException( FacebookCallback<Sharer.Result> callback, final Exception exception) { if (exception instanceof FacebookException) { invokeOnErrorCallback(callback, (FacebookException) exception); return; } invokeCallbackWithError( callback, "Error preparing share content: " + exception.getLocalizedMessage()); }
} else if (shareContent instanceof SharePhotoContent) { final SharePhotoContent photoContent = (SharePhotoContent) shareContent; List<String> photoUrls = ShareInternalUtility.getPhotoUrls( photoContent, callId); } else if (shareContent instanceof ShareVideoContent) { final ShareVideoContent videoContent = (ShareVideoContent) shareContent; String videoUrl = ShareInternalUtility.getVideoUrl(videoContent, callId); final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent; try { JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall( callId, openGraphContent); openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject( openGraphActionJSON, false); nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError); List<Bundle> mediaInfos = ShareInternalUtility.getMediaInfos( mediaContent, callId); Bundle attachmentUrlsBundle = ShareInternalUtility.getTextureUrlBundle( cameraEffectContent, callId); (ShareStoryContent) shareContent; Bundle mediaInfo = ShareInternalUtility.getBackgroundAssetMediaInfo(storyContent, callId);
private static void issueResponse( final UploadContext uploadContext, final FacebookException error, final String videoId) { // Remove the UploadContext synchronously // Once the UploadContext is removed, this is the only reference to it. removePendingUpload(uploadContext); Utility.closeQuietly(uploadContext.videoStream); if (uploadContext.callback != null) { if (error != null) { ShareInternalUtility.invokeOnErrorCallback(uploadContext.callback, error); } else if (uploadContext.isCanceled) { ShareInternalUtility.invokeOnCancelCallback(uploadContext.callback); } else { ShareInternalUtility.invokeOnSuccessCallback(uploadContext.callback, videoId); } } }
/** * 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); }
@Override public boolean onActivityResult(int resultCode, Intent data) { return ShareInternalUtility.handleActivityResult( getRequestCode(), resultCode, data, resultProcessor); } };
public static void invokeCallbackWithResults( FacebookCallback<Sharer.Result> callback, final String postId, final GraphResponse graphResponse) { FacebookRequestError requestError = graphResponse.getError(); if (requestError != null) { String errorMessage = requestError.getErrorMessage(); if (Utility.isNullOrEmpty(errorMessage)) { errorMessage = "Unexpected error sharing."; } invokeOnErrorCallback(callback, graphResponse, errorMessage); } else { invokeOnSuccessCallback(callback, postId); } }
value = jsonObject.get(key); if (value instanceof JSONObject) { value = removeNamespacesFromOGJsonObject((JSONObject) value, true); } else if (value instanceof JSONArray) { value = removeNamespacesFromOGJsonArray((JSONArray) value, true); Pair<String, String> fieldNameAndNamespace = getFieldNameAndNamespaceFromFullName( key); String namespace = fieldNameAndNamespace.first;
public static JSONArray removeNamespacesFromOGJsonArray( JSONArray jsonArray, boolean requireNamespace) throws JSONException { JSONArray newArray = new JSONArray(); for (int i = 0; i < jsonArray.length(); ++i) { Object value = jsonArray.get(i); if (value instanceof JSONArray) { value = removeNamespacesFromOGJsonArray((JSONArray) value, requireNamespace); } else if (value instanceof JSONObject) { value = removeNamespacesFromOGJsonObject((JSONObject) value, requireNamespace); } newArray.put(value); } return newArray; }
@Override protected void registerCallbackImpl( final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) { ShareInternalUtility.registerSharerCallback(getRequestCode(), callbackManager, callback); }
) throws FileNotFoundException { if (Utility.isFileUri(imageUri)) { return newUploadStagingResourceWithImageRequest( accessToken, new File(imageUri.getPath()),
public static Bundle create(ShareOpenGraphContent shareOpenGraphContent) { Bundle params = createBaseParameters(shareOpenGraphContent); Utility.putNonEmptyString( params, ShareConstants.WEB_DIALOG_PARAM_ACTION_TYPE, shareOpenGraphContent.getAction().getActionType()); try { JSONObject ogJSON = ShareInternalUtility.toJSONObjectForWeb(shareOpenGraphContent); ogJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(ogJSON, false); if (ogJSON != null) { Utility.putNonEmptyString( params, ShareConstants.WEB_DIALOG_PARAM_ACTION_PROPERTIES, ogJSON.toString()); } } catch (JSONException e) { throw new FacebookException("Unable to serialize the ShareOpenGraphContent to JSON", e); } return params; }
/** * 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); } }
public static void invokeCallbackWithError( FacebookCallback<Sharer.Result> callback, String error) { invokeOnErrorCallback(callback, error); }
@Test public void testRemoveNamespaceFromNullOGJsonObject() { assertNull(ShareInternalUtility.removeNamespacesFromOGJsonObject(null, false)); }
@Override public void onCancel(AppCall appCall) { invokeOnCancelCallback(callback); }
@Override public void onSuccess(AppCall appCall, Bundle results) { String gesture = ShareInternalUtility.getNativeDialogCompletionGesture(results); if ("cancel".equalsIgnoreCase(gesture)) { callback.onCancel(); } else { callback.onSuccess(new Result(results)); } } };
/** * 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); }
@Override public boolean onActivityResult(int resultCode, Intent data) { return ShareInternalUtility.handleActivityResult( getRequestCode(), resultCode, data, resultProcessor); } };