gpt4 book ai didi

android - 帖子 ID facebook 分享对话框总是在 Android 中返回 null

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:51:44 25 4
gpt4 key购买 nike

我使用测试应用程序 ID 并通过在 facebook 开发站点上的 dash_board 应用程序创建的测试用户登录,使用 facebook sdk 的登录按钮小部件登录时需要 pulish_actions 权限,但结果总是得到 postid = null。这是我的代码:

....

shareDialog = new ShareDialog(MainActivity.this);
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
if (result.getPostId() != null)
Log.e(TAG, result.getPostId());
}

@Override
public void onCancel() {

}

@Override
public void onError(FacebookException e) {

}
});

pulishButton.setOnClickListener(this);
try{
loginButton.setPublishPermissions(new String[]{"publish_actions","publish_stream"});
}catch (FacebookException e){
e.printStackTrace();
}

loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.e(TAG, "success");
loginButton.setEnabled(false);
pulishButton.setEnabled(true);
GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject json, GraphResponse response) {
if (response.getError() != null) {
// handle error
System.out.println("ERROR");
} else {
System.out.println("Success");


} catch (JSONException e) {
e.printStackTrace();
}
}
}

}).executeAsync();
}

@Override
public void onCancel() {
Log.e(TAG, "On cancel");
}

@Override
public void onError(FacebookException e) {
Log.d(TAG, e.toString());
}
});

最佳答案

解决方法是强制ShareDialog使用Feed模式,避免使用FB的App进行分享:

shareDialog.show(linkContent, ShareDialog.Mode.FEED);

我相信这是 FB 的错误。当使用 FB App 进行分享(postId = null)时,他们不会将 postId 发送到 onSuccess 回调,但如果您使用 Feed,他们会发送。

我听说您可以通过使用 Facebook 登录并请求“publish_actions”权限来避免“postId=null”问题。但我认为这不是处理这个问题的正确方法。关于上述许可,Facebook 声明:

Publishing via dialogs or social plugins does not require this permission. Do not request review of this permission if you're only using Share dialog, Feed Dialog, Message Dialog etc, or Social Plugins (e.g. the Like Button.)

Facebook 关于分享对话框的文档:

This does not require Facebook Login or any extended permissions, so it is the easiest way to enable sharing on the web.

关于android - 帖子 ID facebook 分享对话框总是在 Android 中返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32470850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com