问题
I'm able to get profile photo of a user using Facebook SDK 4.0 on android using this -
loginButton = (LoginButton)findViewById(R.id.login_button);
profile = (ImageView)findViewById(R.id.profile);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
String userId = loginResult.getAccessToken().getUserId();
String imageUrl = String.format("https://graph.facebook.com/%s/picture?type=large", userId);
Picasso.with(getBaseContext()).load(imageUrl).into(profile);
}
}
How to go about getting all the photos in a user's profile ? Any help is appreciated.
回答1:
Firstly Make sure the AccessToken has user_photos permission
Then on the app, call a GraphRequest with a photos{link} field
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
try {
//This contains all the photos with array data>>link
JSONObject photosobject = object.getJSONObject("photos");
} catch (Exception e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,picture,photos{link}");
request.setParameters(parameters);
request.executeAsync();
Then please refer to the Facebook Graph API tool to test the values you want https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Dphotos%7Blink%7D
Note: also make sure that you have the latest FacebookSDK
来源:https://stackoverflow.com/questions/31666627/getting-all-the-photos-in-a-users-profile-using-facebook-sdk-on-android