gpt4 book ai didi

android - 从 Facebook Graph-API 获取用户图像

转载 作者:IT老高 更新时间:2023-10-28 23:07:44 24 4
gpt4 key购买 nike

我想在 ListView 中显示用户的个人资料图片。当我尝试从 android 调用 graph-api 来检索图像时,我总是收到以下错误。

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=) 时,我会在这样的 url 上返回图像https://fbcdn-profile-a.akamaihd.net/...

图片以哪种格式发送给我?带有图像引用 (url) 的 JSON?

最佳答案

 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。

欲了解更多详情,请查看 Reference for Graph API

.......................

关于android - 从 Facebook Graph-API 获取用户图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5841710/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com