我正在使用 Facebook SDK 3.0,我需要获取用户登录的个人资料图片。这是我使用的代码:
URL image_value = new URL("http://graph.facebook.com/"+id+"/picture" );
profPict=BitmapFactory.decodeStream(image_value.openConnection().getInputStream());
但我没有得到期望的结果。
我正在使用 Facebook SDK 3.0,我需要获取用户登录的个人资料图片。这是我使用的代码:
URL image_value = new URL("http://graph.facebook.com/"+id+"/picture" );
profPict=BitmapFactory.decodeStream(image_value.openConnection().getInputStream());
但我没有得到期望的结果。
你应该按照以下方式修改你的代码:
URL image_value = new URL("http://graph.facebook.com/"+id+"/picture" );
您可以在此处找到URL的可能GET参数: https://developers.facebook.com/docs/graph-api/reference/user/picture/
我也遇到了同样的问题,请使用https://而不是http://
URL image_value = new URL("https://graph.facebook.com/"+id+"/picture" );
profPict = BitmapFactory.decodeStream(image_value.openConnection().getInputStream());
ProfilePictureView
。setProfileId(String profileId)
。String id = user.getId();
try {
URL url = new URL("http://graph.facebook.com/"+ id+ "/picture?type=large");
String image_path = uri.toString();
System.out.println("image::> " + image_path);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
ProfilePictureView
。您可以在线程内执行以下操作:
String url = "http://graph.facebook.com/"+id+"/picture";
HttpConnection conn = new HttpConnection(url);
conn.openConnection();
Drawable d = Drawable.createFromStream(new BufferedInputStream(conn.getInputStream()), "image");
conn.close();
试试这个...
try {
imageURL = new URL("https://graph.facebook.com/" +
id+ "/picture?type=large");
Log.e("URL", imageURL.toString());
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
try {
bitmap = BitmapFactory.decodeStream(imageURL
.openConnection().getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ProfileDp.setImageBitmap(bitmap);
一旦您的Facebook账户登录到应用程序中,只需执行以下操作:
String url = Profile.getCurrentProfile().getProfilePictureUri(x, y).toString();
x和y分别代表宽度和高度。
请参阅文档: https://developers.facebook.com/docs/reference/android/current/class/Profile/