Reputation: 25
I want to get the profile picture of a page. This is the code but I don't know how to get the image:
new GraphRequest(AccessToken.getCurrentAccessToken(),
"/174034509278825/picture",
null,
HttpMethod.GET,
new GraphRequest.Callback()
{
public void onCompleted(GraphResponse response) {
try { }
catch (JSONException e)
{
e.printStackTrace();
}
}
}
).executeAsync();
Upvotes: 2
Views: 148
Reputation: 103
Response json in get profile picture :
{
"data": {
"is_silhouette": false,
"url": "picture-url"
},
}
My solution code:
AccessToken accessToken = new AccessToken({access-token}
, {app-id}, {user-id}
, null, null, null, null, null);
GraphRequest request = GraphRequest.newGraphPathRequest(
accessToken,
"/{user-id}/picture",
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
try {
JSONObject responseJSONObject = response.getJSONObject();
JSONObject data = responseJSONObject.getJSONObject("data");
Log.i("your tag", "picture url = "+data.getString("url"));
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("redirect", "false");
request.setParameters(parameters);
request.executeAsync();
Upvotes: 2