Mauricio
Mauricio

Reputation: 869

Android Facebook Share Button asking for password again

I'm logged in in my app with a parse session linked with facebook. When I try to share a post to facebook it shows me the facebook window to login again. Why does it do that if I'm already logged in? I checked and the AccessToken.getCurrentAccessToken() is not null when I call the ShareDialog, so there is the session. What's wrong?

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

Upvotes: 1

Views: 186

Answers (3)

Brian Vo
Brian Vo

Reputation: 1001

According to your code, first logInWithReadPermissionsInBackground will execute, a pop-up of facebook show asked for reading permission, then another pop-up should show up and ask for publish permission as linkWithPublishPermissionsInBackground would run. That said you have to see pop-up and confirm twice.

But I am afraid that while ParseFacebookUtils.linkWithPublishPermissionsInBackground(user, WelcomeActivity.this, publish_permission); is executing, you had called presenter.getUserFacebook(AccessToken.getCurrentAccessToken(), user); which navigate user to dashboard ( or any page for logged in user) therefore the current activity (which hold and run linkWithPublishPermissionsInBackground) is terminate. I think you should replace

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

with

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

Upvotes: 1

Gaurav
Gaurav

Reputation: 559

I think your problem is this -

ParseFacebookUtils.logInWithReadPermissionsInBackground(WelcomeActivity.this,
                    read_permissions,

You need to get publish permissions - refer here

Check - logInWithReadPermissionsInBackground

Upvotes: 1

Stanley Ko
Stanley Ko

Reputation: 3497

Did you logged out somewhere before shareButton clicked? Check below code.

LoginManager.getInstance().logOut();

Upvotes: 1

Related Questions