从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//图片?access_token =),然后我得到像这样一个url返回的图像
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/...
在哪种格式的图像传递给我? JSON与引用图像(url)?
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屋!