使用ShareDialog从Android应用程序发布到FaceBook并获取" origin"链接

时间:2015-10-26 14:56:55

标签: android facebook facebook-graph-api

我正在从Android应用程序向FB发布照片。我希望帖子有一个指向我的应用页面的链接,如附带的屏幕截图所示。我在FB文档中的任何地方都找不到关于这种链接的任何解释。

当我使用ShareApi.share(...)时;它开箱即用。我真的希望它能与ShareDialog或Intent一起使用,因为它可以提供更好的用户体验。

我希望在使用这样的Intent时会发生这种情况(编码较少,用户获得了不错的FB体验,但链接没有出现在帖子上):

shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_TEXT, shareText);
shareIntent.setClassName(packageName, activityName);
AnalyticsFactory.get().trackEvent("shareUsing", packageName);
activity.startActivity(shareIntent);

这就是我通过SDK使用它的方式,链接确实显示在帖子上:

private void sharePhoto(Bitmap bitmap, String text) {

// Build SharePhoto
SharePhoto.Builder photoBuilder = new SharePhoto.Builder();
photoBuilder.setBitmap(bitmap);
photoBuilder.setCaption(text);
final SharePhoto sharePhoto = photoBuilder.build();

// Share Call Back
final FacebookCallback<Sharer.Result> shareCallback = new FacebookCallback<Sharer.Result>() {
  boolean userToasted = false;
  @Override
  public void onCancel() {
    Log.e(TAG, "Called onCancel from facebook share. This shouldn't happen since no dialog is presented");
  }

  @Override
  public void onError(FacebookException error)
  {
    Toast.makeText(activityContext, getString(R.string.scoompa_facebook_post_error,error.getMessage()), Toast.LENGTH_LONG).show();
    Log.e(TAG, "Facebook share error + [" + error + "]");
  }

  @Override
  public void onSuccess(Sharer.Result result) {
    // In case of mutliple share, we toast once on the first photo, hoping everything will go smoothly
    if (!userToasted) {
      int resId = paths.size() > 1 ? R.string.scoompa_facebook_posted_plural : R.string.scoompa_facebook_posted;
      Toast.makeText(activityContext, resId, Toast.LENGTH_LONG).show();
      userToasted = true;
    }
  }
};

// Share Photo
ArrayList<SharePhoto> photos = new ArrayList<>();
photos.add(sharePhoto);

// Create a Photo Share
final SharePhotoContent.Builder builder = new SharePhotoContent.Builder();
builder.setPhotos(photos);
SharePhotoContent sharePhotoContent = builder.build();

ShareApi.share(sharePhotoContent, shareCallback);

The link I want to have is circled in red

0 个答案:

没有答案