本文介绍了发布 ID facebook 共享对话框在 Android 中始终返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I used test app id and log on by test user create at dash_board app on facebook develop site, require pulish_actions permission when login using login button widget of facebook sdk but result get postid always = null.Here is my code:

....

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进行分享:

The solution is to force ShareDialog to use Feed mode and avoid using FB's App for sharing:

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

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

I believe this is a bug by FB. They don't send postId to onSuccess callback when using FB App for sharing (postId = null), but they do if you use Feed.

我听说您可以通过使用 Facebook 登录并要求publish_actions"权限来避免postId=null"问题.但我不认为这是处理这个问题的正确方法.关于提到的许可 Facebook 声明:

I've heard you can avoid the "postId=null" problem by using Facebook Login and demanding "publish_actions" permission. But I don't think this is the correct way to deal with this problem. Regarding the mentioned permission Facebook states:

通过对话框或社交插件发布不需要此权限.如果您仅使用共享对话框、Feed 对话框、消息对话框等或社交插件(例如赞"按钮),请勿请求审核此权限.

Facebook 的共享对话框文档:

Facebook's docs on Share Dialog:

这不需要 Facebook 登录或任何扩展权限,因此它是在网络上启用共享的最简单方法.

这篇关于发布 ID facebook 共享对话框在 Android 中始终返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 05:22
查看更多