在Android Facebook SDK中使用共享对话框。如何知道用户是否实际分享或取消共享活动? [英] Using share dialog in Android Facebook SDK. How to know is user actually shared or cancelled sharing activity?

查看:176
本文介绍了在Android Facebook SDK中使用共享对话框。如何知道用户是否实际分享或取消共享活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照 https://这里所述为Android应用添加了共享功能developers.facebook.com/docs/android/share-dialog/#setup

但是我注意到,如果用户被取消共享活动,则完全被调用

But I have noticed that if user is cancelled sharing activity onComplete is called anyway

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
        @Override
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.e("Activity", String.format("Error: %s", error.toString()));
        }

        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.e("Activity", "Success!");
        }
    });
}

我还查看了Bundle返回的内容。即使我取消共享对话框,我得到

I have also looked in to Bundle which is returned. Even if I cancel share dialog i get

com.facebook.platform.extra.DID_COMPLETE=true

如何获取用户真正在Facebook上共享数据的结果? (没有使用Facebook按钮进行单独登录,也许需要添加一些权限?)

How can I get result that user really shared data on facebook? (Without making separate login with facebook button. Maybe some permissions need to be added?)

推荐答案

请参阅 https://developers.facebook.com/docs/android/share-dialog/#handling-responses

您可以通过调用

String gesture = FacebookDialog.getNativeDialogCompletionGesture(data);
if (gesture != null) {
  if ("post".equals(gesture)) {
    // the user hit Post
  } else if ("cancel".equals(gesture)) {
    // the user hit cancel
  } else {
    // unknown value
  }
} else {
  // either an error occurred, or your app has never been authorized
}

其中数据是结果束。但是,如果用户已通过您的应用程序登录(即,您至少拥有basic_info权限),它将只返回非空值。如果用户从未登录过或授权您的应用程序,那么您唯一可以看到的是DID_COMPLETE,除非发生错误,否则它始终为真。这是设计的。

where data is the result bundle. However, it will only return a non-null value IF the user has logged in via your app (i.e. you have at least basic_info permissions). If the user has never logged in or authorized your app, then the only thing you'll see is the DID_COMPLETE, and it will always be true unless an error occurred. This is by design.

这篇关于在Android Facebook SDK中使用共享对话框。如何知道用户是否实际分享或取消共享活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆