Search code examples
facebookfacebook-graph-apifirebase-authentication

Can't get facebook user's profile picture without access token


I'm getting user's profile picture in this way: https://graph.facebook.com/USER_ID/picture and everything was fine until today. Today i lunched my app and i started getting default profile pictures instead of real one.

It seems that now i need access token.

not working

https://graph.facebook.com/USER_ID/picture

working

https://graph.facebook.com/USER_ID/picture?access_token=ACCESS_TOKEN

Question

What happened? I haven't changed anything in the code or configuration of the fb app and yesterday everything was working like a charm.

Important to know: My app is in development mode


Solution

  • Depending on your platform, you can get the temporary access token

    Android

     @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        accessToken = AccessToken.getCurrentAccessToken();
    }
    

    iOS

    - (void)viewDidLoad
    {
      [super viewDidLoad];
      NSString *accessToken = [FBSDKAccessToken currentAccessToken];
    }
    

    Javascript

    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        var accessToken = response.authResponse.accessToken;
      } 
    } );
    

    A much more detailed code snippet and explanation can be found here https://developers.facebook.com/docs/facebook-login/access-tokens

    After you get the accessToken, You can then get the user's Facebook profile picture from the Graph API using https://graph.facebook.com/USER_ID/picture?access_token=ACCESS_TOKEN , just as you said.