我在
android中使用Facebook sdk 4.4.0,我想使用图形请求获取用户的当前配置文件图片.怎么做?
我看到人们使用
https://graph.facebook.com/me/picture?access_token=ACCESS_TOKEN
解决方法
首先,您需要调用GraphRequest API来获取用户的所有详细信息,其中API还提供当前配置文件图片的URL.
Bundle params = new Bundle(); params.putString("fields","id,email,gender,cover,picture.type(large)"); new GraphRequest(AccessToken.getCurrentAccessToken(),"me",params,HttpMethod.GET,new GraphRequest.Callback() { @Override public void onCompleted(GraphResponse response) { if (response != null) { try { JSONObject data = response.getJSONObject(); if (data.has("picture")) { String profilePicUrl = data.getJSONObject("picture").getJSONObject("data").getString("url"); Bitmap profilePic= BitmapFactory.decodeStream(profilePicUrl .openConnection().getInputStream()); mImageView.setBitmap(profilePic); } } catch (Exception e) { e.printStackTrace(); } } } }).executeAsync();