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

Viewed 2296

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

2 Answers

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.

I also was getting the default grey facebook profile picture working in Android Studio on Java. I have the following facebook-login version 8.2.0 dependency in Gradle: implementation 'com.facebook.android:facebook-login:8.2.0'.

I code in Android Studio on Java. The solution that worked for me was to fetch the profile picture when signed in using this line:

Uri photoUrl = Profile.getCurrentProfile().getProfilePictureUri(200, 200);

where Profile is from import com.facebook.Profile.

Related