获取首选宽度和高度的脸部资料图片,android?

时间:2016-03-03 06:03:57

标签: android facebook-login user-profile

我正在获取Facebook个人资料信息以及个人资料图片。

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();
}

我收到的回复是

{"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":"wishygupta@yahoo.com","name":"Wishy Gupta"}

我从网址收到的个人资料图片太小了。如何增加其宽度和高度??

4 个答案:

答案 0 :(得分:4)

你可以这样做,

fbProfilePicURL = "https://graph.facebook.com/" + fbID + "/picture?type=large&redirect=true";

只需将type属性更改为enum{small, normal, album, large, square}的任何人。

来源:Documentation

答案 1 :(得分:3)

这将是获得首选大小的API调用:

/me/picture?width=400&height=200

(或redirect=false无法重定向)

type参数是另一种方式,但不是那么具体。虽然,请记住,你不会总是得到特定尺寸的图片,它更像是“最小宽度/高度”。

答案 2 :(得分:2)

使用此类网址获取大图片

http://graph.facebook.com/"+fbId+"/picture?type=large 

所以你的网址会是     http://graph.facebook.com/10153520390508958/picture?type=large 它会将用户重定向到

https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfa1/v/t1.0-1/p200x200/32044_407244053957_1365573_n.jpg?oh=093ba782d1b509d64c7185fb17c1293f&oe=575AC1B2&gda=1465526737_22e158b3e9e01c68ee8ca303f2934170

但会获得更大的图片,尺寸为200×200

答案 3 :(得分:-1)

不要声明两个对象来解析url对象,只需使用下面的代码行:

String profilePicUrl = object.getJSONObject("picture").getJSONObject("data").getString("url");

此处profilePicUrl包含已解析的网址,例如:

https://xxxxxxxx.xx.fbfbf.net/v/t1.1-1/p50x50/11111111_11111111111111111_1111111111111111111_n.jpg?_nc_cat=0&oh=1ac96e312de6b0e9386c04a4462f4175&oe=1A1A1111