Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook SDK - Failed to receive access token

I'm trying to use Facebook SDK in my Android app. Here's the snippet:

Facebook myFacebook = new Facebook("123456789012345");
myFacebook.authorize(LogInScreen.this, 
    new String[] {
        "publish_stream", 
        "email", 
        "user_about_me", 
        "user_birthday", 
        "user_website", 
        "friends_photos", 
        "user_photos"},
    Facebook.FORCE_DIALOG_AUTH,
    new DialogListener(){

        @Override
        public void onCancel() {
            Log.i("Facebook", "Facebook - cancel");
        }

        @Override
        public void onComplete(Bundle arg0) {
            Log.i("Facebook", "Facebook - complete, AccessToken: " + myFacebook.getAccessToken());
        }

        @Override
        public void onError(DialogError arg0) {
            Log.i("Facebook", "Facebook - error");
        }

        @Override
        public void onFacebookError(FacebookError error) {
            Log.i("Facebook", "Facebook - facebookError: " + error);
                    try {
                        myFacebook.logout(LogInScreen.this);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }}
    );
}
});

When I run this code, I can log in with my main facebook account, but when I try to use any other fb account I got error "Failed to receive access token". Am I missing something?

like image 403
Seraphis Avatar asked Dec 07 '22 17:12

Seraphis


2 Answers

The problem was that the facebook app was set to sandbox mode, so only developer accounts could get access token from app's ID.

like image 63
Seraphis Avatar answered Dec 24 '22 12:12

Seraphis


I had the same problem, but sandbox wasn't solution. I had some restrictions about countries and my country wasn't there. I added it and it resolved my problem.

like image 33
Kornel Avatar answered Dec 24 '22 13:12

Kornel