Reputation: 11
I want to fetch all photos of user who is logged in to my app using facebook . I am getting 200 error code
Bundle bundle = new Bundle();
bundle.putString("fields", "user_photos");
String id = com.facebook.Profile.getCurrentProfile().getId();
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + id + "/photos",
bundle,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
JSONArray jsonPhotos = response.getJSONObject().getJSONArray("data");
Log.d("", "onCompleted: ");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
Response
{Response: responseCode: 200, graphObject: {"data":[]}, error: null}
Upvotes: 1
Views: 60
Reputation: 496
HTTP 200 means that your request is OK.
You need https://graph.facebook.com/[uid]/albums?access_token=[AUTH_TOKEN] to get JSON array of all the albums of a user.
You will get three important things from here id - album id, name - album name, and type - album type.
The permission required is user_photos
Profile Pictures are under "Profile Pictures" album. To get to profile album, you need to look into albums array, iterate through the JSON result-set, until you get an album with name = Profile Pictures and type = profile. Get id of this object. This is the profile pictures album.
Now you can access it similar to you access any other album. That is, https://graph.facebook.com/[ALBUM_ID]/photos?access_token=[AUTH_TOKEN] this will list all the profile pictures of the user ever uploaded.
refer: http://developers.facebook.com/docs/reference/api/
Upvotes: 1