从 Facebook Graph-API 获取用户图片 [英] Get user image from Facebook Graph-API
问题描述
我想在列表视图中显示用户的个人资料图片.当我尝试从android调用graph-api来检索图像时,总是出现以下错误.
I want to show the users profile picture in a list view. When I try to call the graph-api from android to retrieve the image, I always get the following error.
java.io.IOException: Hostname <fbcdn-profile-a.akamaihd.net> was not verified
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:170)
at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:398)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.sendRequest(HttpURLConnection.java:1224)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequestInternal(HttpURLConnection.java:1558)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequest(HttpURLConnection.java:1551)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1052)
at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.getInputStream(HttpsURLConnection.java:252)
at com.facebook.android.Util.openUrl(Util.java:200)
at com.facebook.android.Facebook.request(Facebook.java:559)
这是我使用的代码:
private static void retrieveProfilePicture(String userId) throws MalformedURLException, IOException{
facebook = FacebookHelper.getInstance();
Bundle bundle = new Bundle();
bundle.putString(Facebook.TOKEN, facebook.getAccessToken());
Object picture = facebook.request("/"+userId+"/picture", bundle, "GET");
当我在浏览器(https://graph.facebook.com//picture?access_token=)中执行相同的调用时,我会在这样的网址上返回图像https://fbcdn-profile-a.akamaihd.net/...
When I do the same call in the browser (https://graph.facebook.com//picture?access_token=), then I get the image returned on a url like this
https://fbcdn-profile-a.akamaihd.net/...
图片以哪种格式发送给我?带有图像(url)引用的 JSON?
In which format is the image delivered to me? JSON with a ref to image (url)?
推荐答案
ImageView user_picture;
userpicture=(ImageView)findViewById(R.id.userpicture);
URL img_value = null;
img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
userpicture.setImageBitmap(mIcon1);
其中 ID 是您的个人资料 ID.
Where ID is one your profile ID.
有关更多详细信息,请查看此Graph API 参考
For Further details check this Reference for Graph API
................................
............................
这篇关于从 Facebook Graph-API 获取用户图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!