Reputation: 11999
I am getting the facebook profile information and also the profile picture.
public void getProfileInformationFacebook(AccessToken accToken) {
GraphRequest request = GraphRequest.newMeRequest(
accToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
Log.e("object", object.toString());
String fbId = null;
String fbEmail = null;
String fbName = null;
String fbUrl = null;
try {
fbId = object.getString("id");
fbEmail = object.getString("email");
fbName = object.getString("name");
JSONObject picture = object.getJSONObject("picture");
JSONObject pictureData = picture.getJSONObject("data");
fbUrl = pictureData.getString("url");
} catch (JSONException e) {
e.printStackTrace();
} finally {
regDetails("Facebook", fbId, fbName, fbEmail, fbUrl);
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,location,birthday,picture");
request.setParameters(parameters);
request.executeAsync();
}
The response I receive is this
{"picture":{"data":{"url":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xfa1\/v\/t1.0-1\/c0.0.50.50\/p50x50\/32044_407244053957_1365573_n.jpg?oh=df9a5f89e6b19af9942cb948c952a026&oe=57559847&__gda__=1465809549_0402ad5c0dcf64f932ceabc982b02f5f","is_silhouette":false}},"id":"10153520390508958","email":"[email protected]","name":"Wishy Gupta"}
And the profile image I receive from the URL is too small. How to increase its width and height??
Upvotes: 1
Views: 868
Reputation: 1
Don't declare two objects to parse the url object, just use below line of code :
String profilePicUrl = object.getJSONObject("picture").getJSONObject("data").getString("url");
Here profilePicUrl
, contains the parsed url, something like :
Upvotes: -1
Reputation: 73984
This would be the API call to get a preferred size:
/me/picture?width=400&height=200
(or with redirect=false
to not get redirected)
The type parameter is another way, but it´s not that specific. Although, keep in mind that you will not always get a picture in that specific size, it´s more like the "minimum width/height".
Upvotes: 3
Reputation: 1077
Use this type of url to get large picture
http://graph.facebook.com/"+fbId+"/picture?type=large
so your url will be http://graph.facebook.com/10153520390508958/picture?type=large it will redirect user to
but will get larger picture with size 200 by 200
Upvotes: 2
Reputation: 2534
You can do this,
fbProfilePicURL = "https://graph.facebook.com/" + fbID + "/picture?type=large&redirect=true";
Just change the type
attribute to anyone of enum{small, normal, album, large, square}
.
Source : Documentation.
Upvotes: 4