我要显示用户在列表视图资料图片。 当我尝试调用图形-API从Android的检索图像,我总是得到下面的错误。
java.io.IOException异常:主机名< fbcdn-profile-a.akamaihd.net>未验证
在org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:170)
在org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:398)
在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.sendRequest(HttpURLConnection.java:1224)
在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequestInternal(HttpURLConnection.java:1558)
在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequest(HttpURLConnection.java:1551)
在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1052)
在org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.getInputStream(HttpsURLConnection.java:252)
在com.facebook.android.Util.openUrl(Util.java:200)
在com.facebook.android.Facebook.request(Facebook.java:559)
这是我所用的code:
私有静态无效retrieveProfilePicture(字符串userid)抛出MalformedURLException的,IOException异常{
Facebook的= FacebookHelper.getInstance();
束束=新包();
bundle.putString(Facebook.TOKEN,facebook.getAccessToken());
对象画面= facebook.request(/+用户id +/图片,捆绑,GET);
当我做同样的呼吁在浏览器(https://graph.facebook.com//picture?access_token=),然后我得到返回的图像上像这样的网址
HTTPS://fbcdn-profile-a.akamaihd.net / ...
在哪种格式交付给我的形象呢? JSON与裁判图像(URL)?
解决方案 ImageView的user_picture;
userpicture =(ImageView的)findViewById(R.id.userpicture);
URL img_value = NULL;
img_value =新的URL(http://graph.facebook.com/+编号+?/图像类型=大);
位图mIcon1 = BitmapFactory.de codeStream(img_value.openConnection()的getInputStream());
userpicture.setImageBitmap(mIcon1);
其中id是您的个人资料的ID。
有关进一步的细节检查这个参考图形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)
This is the code used by me:
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");
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/...
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);
Where ID is one your profile ID.
For Further details check this Reference for Graph API
............................