public static void registerSharerCallback( final int requestCode, final CallbackManager callbackManager, final FacebookCallback<Sharer.Result> callback) { if (!(callbackManager instanceof CallbackManagerImpl)) { throw new FacebookException("Unexpected CallbackManager, " + "please use the provided Factory."); } ((CallbackManagerImpl) callbackManager).registerCallback( requestCode, new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { return handleActivityResult( requestCode, resultCode, data, getShareResultProcessor(callback)); } }); }
public static synchronized void uploadAsync( ShareVideoContent videoContent, String graphNode, FacebookCallback<Sharer.Result> callback) throws FileNotFoundException { if (!initialized) { registerAccessTokenTracker(); initialized = true; } Validate.notNull(videoContent, "videoContent"); Validate.notNull(graphNode, "graphNode"); ShareVideo video = videoContent.getVideo(); Validate.notNull(video, "videoContent.video"); Uri videoUri = video.getLocalUrl(); Validate.notNull(videoUri, "videoContent.video.localUrl"); UploadContext uploadContext = new UploadContext(videoContent, graphNode, callback); uploadContext.initialize(); pendingUploads.add(uploadContext); enqueueUploadStart( uploadContext, 0); }
private UploadContext( ShareVideoContent videoContent, String graphNode, FacebookCallback<Sharer.Result> callback) { // Store off the access token right away so that under no circumstances will we // end up with different tokens between phases. We will rely on the access token tracker // to cancel pending uploads. this.accessToken = AccessToken.getCurrentAccessToken(); this.videoUri = videoContent.getVideo().getLocalUrl(); this.title = videoContent.getContentTitle(); this.description = videoContent.getContentDescription(); this.ref = videoContent.getRef(); this.graphNode = graphNode; this.callback = callback; this.params = videoContent.getVideo().getParameters(); }
private void initFB() { FacebookSdk.sdkInitialize(mContext); callbackManager = CallbackManager.Factory.create(); mShareDialog = new ShareDialog(mContext); // this part is optional mShareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { } @Override public void onCancel() { } @Override public void onError(FacebookException error) { } }); }
public static synchronized void uploadAsync( ShareVideoContent videoContent, String targetId, FacebookCallback<Sharer.Result> callback) throws FileNotFoundException { if (!initialized) { registerAccessTokenTracker(); initialized = true; } Validate.notNull(videoContent, "videoContent"); Validate.notNull(targetId, "targetId"); ShareVideo video = videoContent.getVideo(); Validate.notNull(video, "videoContent.video"); Uri videoUri = video.getLocalUrl(); Validate.notNull(videoUri, "videoContent.video.localUrl"); UploadContext uploadContext = new UploadContext(videoContent, targetId, callback); uploadContext.initialize(); pendingUploads.add(uploadContext); enqueueUploadStart( uploadContext, 0); }
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()); }
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); } }
static void invokeOnSuccessCallback( FacebookCallback<Sharer.Result> callback, String postId) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_SUCCEEDED, null); if (callback != null) { callback.onSuccess(new Sharer.Result(postId)); } }
static void invokeOnErrorCallback( FacebookCallback<Sharer.Result> callback, GraphResponse response, String message) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_ERROR, message); if (callback != null) { callback.onError(new FacebookGraphResponseException(response, message)); } }
static void invokeOnErrorCallback( FacebookCallback<Sharer.Result> callback, String message) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_ERROR, message); if (callback != null) { callback.onError(new FacebookException(message)); } }
static void invokeOnErrorCallback( FacebookCallback<Sharer.Result> callback, FacebookException ex) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_ERROR, ex.getMessage()); if (callback != null) { callback.onError(ex); } }
@Override protected FacebookDialogBase<ShareContent, Sharer.Result> getDialog() { final ShareDialog dialog; if (ShareButton.this.getFragment() != null) { dialog = new ShareDialog(ShareButton.this.getFragment() , getRequestCode()); } else { dialog = new ShareDialog(getActivity(), getRequestCode()); } return dialog; }
@Override protected FacebookDialogBase<ShareContent, Sharer.Result> getDialog() { final MessageDialog dialog; if (SendButton.this.getFragment() != null) { dialog = new MessageDialog(SendButton.this.getFragment() , getRequestCode()); } else { dialog = new MessageDialog(getActivity(), getRequestCode()); } return dialog; }
/** * Share content on facebook wall * * @param activity the activity * @param callback the callback to receive a result of this share * @param url the url you wish to share * @param quote the text you wish to associate with the url shared */ private void shareLinkOnFacebook(@NonNull final Activity activity, @NonNull final FacebookShareResultCallback callback, @NonNull String url, @Nullable String quote) { ShareDialog shareDialog = new ShareDialog(activity); shareDialog.registerCallback(mCallbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { callback.onFacebookShareSuccess(result); } @Override public void onCancel() { callback.onFacebookShareCancel(); } @Override public void onError(FacebookException error) { callback.onFacebookShareError(error); } }, RC_FACEBOOK_SHARE); if (ShareDialog.canShow(ShareLinkContent.class)) { ShareLinkContent linkContent = new ShareLinkContent.Builder().setContentUrl(Uri.parse(url)) .setQuote(quote) .build(); shareDialog.show(linkContent); } else { callback.onFacebookShareCannotShowDialog(); } }
private void setUpShareConfig(String url, ShareDialog shareDialog) { if (ShareDialog.canShow(ShareLinkContent.class)) { ShareLinkContent shareLinkContent = new ShareLinkContent.Builder() .setContentUrl(Uri.parse(url)) .build(); shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { if (onFacebookShareEvent != null) { onFacebookShareEvent.onShareSuccessFacebook(); } } @Override public void onCancel() { if (onFacebookShareEvent != null) { onFacebookShareEvent.onShareCanceledFacebook(); } } @Override public void onError(FacebookException error) { error.printStackTrace(); } }); shareDialog.show(shareLinkContent); } }
private static void invokeOnSuccessCallback( FacebookCallback<Sharer.Result> callback, String postId) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_SUCCEEDED, null); if (callback != null) { callback.onSuccess(new Sharer.Result(postId)); } }
private static void invokeOnErrorCallback( FacebookCallback<Sharer.Result> callback, GraphResponse response, String message) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_ERROR, message); if (callback != null) { callback.onError(new FacebookGraphResponseException(response, message)); } }
private static void invokeOnErrorCallback( FacebookCallback<Sharer.Result> callback, String message) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_ERROR, message); if (callback != null) { callback.onError(new FacebookException(message)); } }
private static void invokeOnErrorCallback( FacebookCallback<Sharer.Result> callback, FacebookException ex) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_ERROR, ex.getMessage()); if (callback != null) { callback.onError(ex); } }
@Override public void onSuccess(Sharer.Result result) { if (result.getPostId() != null) { String title = getString(R.string.success); String id = result.getPostId(); String alertMessage = getString(R.string.successfully_posted_post, id); showResult(title, alertMessage); } }
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(getLayoutId(), null); ButterKnife.bind(this, view); shareDialog = new ShareDialog(this); CallbackManager callbackManager = CallbackManager.Factory.create(); shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { } @Override public void onCancel() { } @Override public void onError(FacebookException error) { TextToast.shortShow(getString(R.string.share_fail)); } }); pager.setOnPageChangeListener(this); pager.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ViewPager>() { @Override public void onRefresh(PullToRefreshBase<ViewPager> refreshView) { refresh(); } }); adapter = new FragmentAdapter(getChildFragmentManager(), new ArrayList<AbsBaseFragment>()); pager.setAdapter(adapter); init(); instance=this; return view; }
public void onShareResult(){ FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); final ShareDialog shareDialog = new ShareDialog(this); shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { } @Override public void onError(FacebookException error) { } @Override public void onCancel() { } }); if (shareDialog.canShow(ShareLinkContent.class)) { String link = "http://203.151.92.187:8080/courseSchedule?username=" + SingletonID.getInstance().getUserName(); ShareLinkContent linkContent = new ShareLinkContent.Builder() .setContentTitle("CE SMART TRACKER") .setContentDescription("วิชาที่เรียน") .setContentUrl(Uri.parse(link)) .build(); shareDialog.show(linkContent); } else Toast.makeText(getApplicationContext(),"ลงทะเบียนผ่าน Facebook",Toast.LENGTH_SHORT).show(); }
/** * Shares the app on Facebook */ private void shareOnFacebook() { analytics.sendEvent("facebook", "attempt_post"); // Set up all of the info ShareLinkContent content = new ShareLinkContent.Builder() .setContentTitle(getString(R.string.social_facebook_title, "Android")) .setContentDescription(getString(R.string.social_facebook_description_android)) .setContentUrl(Uri.parse(getString(R.string.social_link_android))) .setImageUrl(Uri.parse(getString(R.string.social_facebook_image))) .build(); // Show the dialog ShareDialog dialog = new ShareDialog(this); dialog.registerCallback(facebookCallbackManager, new FacebookCallback<Sharer.Result>() { @Override public void onSuccess(Sharer.Result result) { if (result.getPostId() != null) { // Let the user know they posted successfully Utils.toast(DrawerActivity.this, R.string.social_post_success); analytics.sendEvent("facebook", "successful_post"); } else { Timber.i("Facebook post cancelled"); } } @Override public void onCancel() { Timber.i("Facebook post cancelled"); } @Override public void onError(FacebookException e) { Timber.e(e, "Error posting to Facebook"); Utils.toast(DrawerActivity.this, R.string.social_post_failure); analytics.sendEvent("facebook", "failed_post"); } }); dialog.show(content); }
private UploadContext( ShareVideoContent videoContent, String targetId, FacebookCallback<Sharer.Result> callback) { // Store off the access token right away so that under no circumstances will we // end up with different tokens between phases. We will rely on the access token tracker // to cancel pending uploads. this.accessToken = AccessToken.getCurrentAccessToken(); this.videoUri = videoContent.getVideo().getLocalUrl(); this.title = videoContent.getContentTitle(); this.description = videoContent.getContentDescription(); this.ref = videoContent.getRef(); this.targetId = targetId; this.callback = callback; }
public static void invokeCallbackWithError( FacebookCallback<Sharer.Result> callback, String error) { invokeOnErrorCallback(callback, error); }
static void invokeOnCancelCallback(FacebookCallback<Sharer.Result> callback) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_CANCELLED, null); if (callback != null) { callback.onCancel(); } }
public static synchronized void uploadAsync( ShareVideoContent videoContent, FacebookCallback<Sharer.Result> callback) throws FileNotFoundException { uploadAsync(videoContent, "me", callback); }
private static void invokeOnCancelCallback(FacebookCallback<Sharer.Result> callback) { logShareResult(AnalyticsEvents.PARAMETER_SHARE_OUTCOME_CANCELLED, null); if (callback != null) { callback.onCancel(); } }