![](/img/trans.png)
[英]How do I get the user's name, email, and profile picture when the user logs in with their Facebook account?
[英]White question mark while trying to get user's Facebook profile picture in Android
我将应用程序范围的ID存储在我的数据库中,希望通过图谱API从它们中获取个人资料图片。
这段代码:
String url = "https://graph.facebook.com/" + mate.getFacebookId() + "/picture?type=large";
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = null;
HttpEntity entity = null;
try {
response = httpClient.execute(httpGet);
} catch (IOException e) {
e.printStackTrace();
}
if (response != null) {
entity = response.getEntity();
}
byte[] data = null;
try {
data = EntityUtils.toByteArray(entity);
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap = null;
if (data != null) {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
}
return bitmap;
...不起作用并返回白色问号,为什么?
网址' https://graph.facebook.com/800397776713349/picture?type=normal '在chrome中可以正常使用。
此行上的分号丢失:
String url = "https://graph.facebook.com/" + mate.getFacebookId() + "/picture?type=large"
看来您使用的是无效的Facebook ID。 检查mate.getFacebookId()是否返回有效的 ID。 使用有效的ID时,我可以在AsyncTask中成功返回图像:
在主线程内使用(onCreate,onActivityCreated等):
GetImage retrieve = new GetImage((ImageView)findViewById(R.id.yourimageview));
retrieve.execute();
的getImage:
class GetImage extends AsyncTask<String, Void, Bitmap>
{
private ImageView view;
public GetImage(ImageView view)
{
this.view = view;
}
@Override
protected Bitmap doInBackground(String... params)
{
//Your exact code goes here
}
@Override
protected void onPostExecute(Bitmap b)
{
view.setImageBitmap(b);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.