7
votes

I see there's a new version of Facebook SDK (3.0) that deprecates the old Facebook class and introduces a new way of logging in using the Session class.

I quickly wrote a simple app using the new login API:

public class MainActivity extends Activity {

private Session mFacebookSession;

private StatusCallback fbStatusCallback = new StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        Log.v("dbg", "state: " + state);
        Log.v("dbg", "session: " + session);
    }
};

public void bc(View view)
{
    mFacebookSession = Session.openActiveSession(this, true, fbStatusCallback);
}
//etc..
}

The callback should get called twice, first for destroying the actual session token and second for getting a new access token. Of course, my app id is set as a meta-data in my manifest file, etc.

When I execute the code, the Facebook Login dialog appears, I input my username and password and then it closes.

However, in my log I only see this:

01-17 03:28:01.587: V/dbg(7002): state: OPENING
01-17 03:28:01.587: V/dbg(7002): session: {Session state:OPENING, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:xxxxxxxxxxxxxxx}

As a result, if I try to call mFacebookSession.getAccessToken() i get an empty string (not null).

What seems to be the problem?

HOW I SOLVED THIS (LATER)

I have overridden onActivityResult and called Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);

2
Are you 100% confident your appID is correct and you have set up the facebook app correctly? I had a similar problem and it came down to me using the id of another of my facebook apps - seaplain
Well, the login dialog displays my application name and if I add some permissions (i also found a way to add them but didn't include in this code to keep things simple for everybody to understand), they are also displayed correctly. - Sterpu Mihai
hmm.. I now realize that in the *Native Android App' section I didn't put any hash. But why don't I get an Exception via the callback? - Sterpu Mihai
I honestly don't know, I wasn't getting any exceptions either. At least you found your answer - seaplain
Did you also override the onActivityResult method in your MainActivity class, and call Session.getActiveSession().onActivityResult(...)? - Ming Li

2 Answers

1
votes

Im just going to put this here for anyone else:

The Facebook SDK is really terrible at letting you know you have forgotten something. If it's not working for you double check your Facebook app and make sure you haven't forgotten something or put in the wrong values. In my case the appID was wrong in Sterpu Mihai's case it was the hash key

0
votes

another thing that would cause the same error (Token_removed)

Android Facebook SDK3.0, session state OPENING