分享

发布ID Facebook分享对话框在Android中始终返回null

 印度阿三17 2019-10-10

我使用了测试应用程序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发送到onSuccess回调(postId = null),但是如果您使用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.

来源:https://www./content-4-499901.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多