12

I want to implement Facebook Login in my application, but here I am getting problem while trying to login i.e :

**{Session state:OPENING, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:1xxxxxxxxxxxxxxx}**

and sometimes this one also:

  **{Session state:CLOSED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[]}, appId:1xxxxxxxxxxxxxxx}**

Note: The above problem occurs when my device already has installed NATIVE FACEBOOK APP, if I uninstall the Facebook app it works absolutely fine. Can Anyone please help me out what the matter is ?

Thanks in advance

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143

6 Answers6

12

Be sure to override in your Activity the onActivityResult method:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);

}
koma
  • 121
  • 1
  • 3
5

Try

AccessToken.getCurrentAccessToken().getToken();

instead of using the toString() function.

bergjs
  • 125
  • 2
  • 6
2

I know this is an old ticket, but no one has appeared to give the correct answer. The token is removed from toString to prevent token exposure.

com.facebook.LoggingBehavior (from line 29):

/**
 * Indicates that access tokens should be logged as part of the request logging; normally they are not.
 */
INCLUDE_ACCESS_TOKENS,

com.facebook.AccessToken (from line 322):

private String tokenToString() {
    if (this.token == null) {
        return "null";
    } else if (Settings.isLoggingBehaviorEnabled(LoggingBehavior.INCLUDE_ACCESS_TOKENS)) {
        return this.token;
    } else {
        return "ACCESS_TOKEN_REMOVED";
    }
}

To show the token in toString requests simply add logging to the settings :

    Settings.addLoggingBehavior( LoggingBehavior.INCLUDE_ACCESS_TOKENS );
    this.mUiLifecycleHelper = new UiLifecycleHelper( this, this.mCallback );
    this.mUiLifecycleHelper.onCreate( savedInstanceState );

Hope this helps others with the same issue.

James Lockhart
  • 1,030
  • 11
  • 17
2

Just a heads up. This exact case was happening to me. My login stopped working just because I changed my Activity launch mode in Manifest.xml file from:

android:launchMode="singleInstance"

to

android:launchMode="singleTask"

So, I changed it again to singleInstance and it is working fine now.

joao2fast4u
  • 6,868
  • 5
  • 28
  • 42
0

This maybe happening because you didn't add the hashkey in your Facebook app. Check out this link Generating Hashkey for Android to learn how to generate hashkey.

This was happening to me too. It started working after i added the hashkey in Facebook app.

Community
  • 1
  • 1
Apoorv
  • 13,470
  • 4
  • 27
  • 33
  • The `hashkey` for running directly from Eclipse and by running APK will be different. Which one are you trying? – Apoorv Feb 18 '14 at 11:02
  • I am running the app on my device, one thing more I would like to add is I have tried the APP_ID of Scrumptions Sample too, that too is not working – Gaurav Arora Feb 18 '14 at 11:03
  • As OP said that "The above problem occurs when my device already has installed NATIVE FACEBOOK APP, if I uninstall the Facebook app it works absolutely fine.". I believe that now there should not be issue in the hashkey – Ajay S Feb 22 '14 at 09:30
  • Are `Single Sign On` and `Deep Linking` turned on in your Facebook app?Also the app should be not be in sandbox mode. – Apoorv Feb 22 '14 at 09:32
  • @Apoorv I have made single On and Deep Linking On, No progress yet. – Gaurav Arora Feb 28 '14 at 07:17
0

This is my working integration of new Facebook SDK 4.1. First you need to init SDKin 4.1 ///

/** if face book SDK is not initialized then initialized.*/ 
    if(!FacebookSdk.isInitialized())
           FacebookSdk.sdkInitialize(BaseActivity.this);    

Now you need callback manger

/** create face book callback factory.*/ 
    if(null == callbackManager)
    callbackManager = CallbackManager.Factory.create();

These are call back.

    public final  FacebookCallback<LoginResult> _mcallbackLogin =    new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            if(loginResult.getAccessToken() != null){
                Log.i("TAG", "LoginButton FacebookCallback onSuccess token : "+ loginResult.getAccessToken().getToken());
              GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject object, GraphResponse response) {
                        if(null != object){
                            Log.e("TAG", object.optString("name"),object.optString("first_name"),object.optString("email"),false).execute();
                        }
                    }
                }).executeAsync();
            }
        }

        @Override
        public void onCancel() {
            Log.e("TAG", "LoginButton FacebookCallback onCancel");
        }

        @Override
        public void onError(FacebookException exception) {
            Log.e("TAG","Exception:: "+exception.getStackTrace());
        }
    };

Now you need register call back on facebook login button

    loginBtn.registerCallback(BaseActivity.callbackManager,_mcallbackLogin);
Emran Hamza
  • 3,829
  • 1
  • 24
  • 20