Post Id facebook share dialog always return null in Android

落花浮王杯 提交于 2019-12-30 18:28:49

问题


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());
        }
    });

回答1:


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

shareDialog.show(linkContent, ShareDialog.Mode.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.

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:

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's docs on Share Dialog:

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




回答2:


Facebook confirmed this issue in their latest update: https://developers.facebook.com/support/bugs/478167629274681/ https://developers.facebook.com/support/bugs/647119912303459/




回答3:


You can't login directly with "publish_action", you have to first login with any read permission then ask for for publish permissions https://developers.facebook.com/docs/facebook-login/permissions/v2.4#publishing



来源:https://stackoverflow.com/questions/32470850/post-id-facebook-share-dialog-always-return-null-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!