Android& Facebook SDK:从/ me /图片图片调用中解码图片 [英] Android & Facebook SDK : decoding pictures from /me/picture graph call
问题描述
编辑:Anwser在这篇文章的结尾。
Anwser at the end of this post.
我想通过内置的Facebook SDK的功能来获得Facebook用户的个人资料图片 Request()
。
I am trying to get a Facebook user's profile picture thanks to the inbuilt Facebook SDK's function Request()
.
我正在使用 / me /图片
调用获取个人资料图片并将其转换为 位图
。
I am using a /me/picture
call to get the profile picture and convert it into a Bitmap
.
该通话正常,但我不知道如何解释和解析从Facebook返回的结果
这是我获得的 JSON
:
Here is the JSON
that I get:
{
FACEBOOK_NON_JSON_RESULT: \\\ \\\JFIF\\\ \\\\\\\\\ \\\ \\\\\\ \\\\\\ \\\ \ u0000\\\ * \\\ \\\ C\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\ \b
}
{ "FACEBOOK_NON_JSON_RESULT" : "����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000\u0004*\u0000��\u0000C\u0000\u0006\u0004\u0005\u0006\u0005\u0004\u0006\u0006\u0005\u0006\u0007\u0007\u0006\b" }
我认为这应该是表示个人资料图片,但我现在不知道该怎么做。
I think this should be representing the profile picture but I don't know what to do with this now.
如果有人可以告诉我如何解码它,将其转换为Bitmap或什么样的数据,我将不胜感激。
If somebody could tell me either how to decode it, convert it to a Bitmap or what kind of data it is, I would be grateful.
注意:我不想使用除Request()之外的任何其他函数,如DecodeStream()或AsyncTask
这是答案:
当新的 Request()
您需要将redirect参数添加到 false
:
When making a new Request()
you need to add the "redirect" parameter to false
:
Bundle params = new Bundle();
params.putBoolean("redirect", false);
这将返回正确的图片网址:
This will return the correct picture URL:
{
"data":{
"is_silhouette":false,
"url":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xpa1\/v\/t1.0-1\/p100x100\/10312434_10152395442477210_2933994167675146084_n.jpg?oh=f3c8cb920c97fcfa4dc5e17462445cbf&oe=54404A3A&__gda__=1412730795_5f288e34e5f6e63cb1c3791dcb142880"
}
}
推荐答案
这个:
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.
详情请参阅:
https://developers.facebook.com/docs/graph-api
这篇关于Android& Facebook SDK:从/ me /图片图片调用中解码图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!