问题描述
我添加了分享功能,如这里所描述的Android应用程序,https://developers.facebook.com/docs/android/share-dialog/#setup
I have added sharing functionality to Android app as described here https://developers.facebook.com/docs/android/share-dialog/#setup
不过,我已经注意到,如果用户被取消分享活动的onComplete反正是名为
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!");
}
});
}
我也期待在捆绑被返回。即使我删除共享对话框我得到
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
您可以告诉用户是否已经取消了通过调用
You can tell if the user has cancelled by calling
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共享对话框。如何知道是用户实际共享或取消共享活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!