Android Facebook分享按钮再次要求输入密码

时间:2017-05-22 16:31:55

标签: android facebook facebook-graph-api parse-platform

我使用与facebook关联的解析会话登录了我的应用。当我尝试向Facebook分享帖子时,它会显示我再次登录的Facebook窗口。如果我已经登录,为什么会这样做呢?当我调用ShareDialog时,我检查并且AccessToken.getCurrentAccessToken()不为null,因此存在会话。怎么了?

WelcomeActivity

public void initializeFacebookButton() {

    if (AccessToken.getCurrentAccessToken() == null)
        ParseFacebookUtils.initialize(this);

    mLoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            progressBar.setVisibility(View.VISIBLE);
            ParseFacebookUtils.logInWithReadPermissionsInBackground(WelcomeActivity.this,
                    read_permissions, new LogInCallback() {
                        @Override
                        public void done(ParseUser user, ParseException e) {
                            progressBar.setVisibility(View.GONE);
                            if (e == null && user !=  null){
                                ParseFacebookUtils.linkWithPublishPermissionsInBackground(user,
                                        WelcomeActivity.this, publish_permission);
                                Log.d(TAG, "logged in");
                                   presenter.getUserFacebook(AccessToken.getCurrentAccessToken(),
                                        user);
                            } else {
                                Log.e(TAG, "Error logging in ");
                            }
                        }
                    });
        }
    });
}

ShareActivity

Button shareButton;

shareButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
                .putString("og:type", "fitness.course")
                .putString("og:title", title)
                .putString("og:description", description)
                .putInt("fitness:duration:value", time_in_seconds)
                .putString("fitness:duration:units", "s")
                .putDouble("fitness:metrics:location:latitude", latitude)
                .putDouble("fitness:metrics:location:longitude", longitude)
                .build();
        ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
                .setActionType("fitness.runs")
                .putObject("fitness:course", object)
                .build();
        ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
                .setPreviewPropertyName("fitness:course")
                .setAction(action)
                .build();

                ShareDialog.show(ShareActivity.this, content);
            }
        });

3 个答案:

答案 0 :(得分:1)

在点击shareButton之前你有没有登出过某个地方? 检查以下代码。

LoginManager.getInstance().logOut();

答案 1 :(得分:1)

我认为你的问题是这个 -

logInWithReadPermissionsInBackground

您需要获得发布权限 - refer here

检查 - #{your div ID}{ background-image: url("backgroundImage.png"); }

答案 2 :(得分:1)

根据你的代码,首先 logInWithReadPermissionsInBackground 将执行,Facebook show的弹出窗口要求阅读权限,然后另一个弹出窗口应该出现并要求发布权限 linkWithPublishPermissionsInBackground 会运行。那说你必须看到弹出并确认两次。

但我害怕这一点 ParseFacebookUtils.linkWithPublishPermissionsInBackground(user, WelcomeActivity.this, publish_permission); 正在执行,你打过电话 presenter.getUserFacebook(AccessToken.getCurrentAccessToken(), user); 它将用户导航到仪表板(或登录用户的任何页面),因此当前活动(保存并运行linkWithPublishPermissionsInBackground)将终止。 我认为你应该替换

ParseFacebookUtils.linkWithPublishPermissionsInBackground(user,
                                    WelcomeActivity.this, publish_permission);
                            Log.d(TAG, "logged in");
                               presenter.getUserFacebook(AccessToken.getCurrentAccessToken(),
                                    user);

ParseFacebookUtils.linkWithPublishPermissionsInBackground(user, WelcomeActivity.this, publish_permission,new LogInCallback(){public void done(ParseUser user, ParseException e) {
 if (e == null && user != null) {
   Log.d(TAG, "logged in");
   presenter.getUserFacebook(AccessToken.getCurrentAccessToken(),user);
 }}});