[英]White question mark while trying to get user's Facebook profile picture in Android
I store app-scoped-ids in my database, hoping to fetch profile pictures from them via the graph API. 我将应用程序范围的ID存储在我的数据库中,希望通过图谱API从它们中获取个人资料图片。
This code: 这段代码:
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;
...does not work and returns a white question mark, why? ...不起作用并返回白色问号,为什么?
The url ' https://graph.facebook.com/800397776713349/picture?type=normal ' works just fine in chrome. 网址' https://graph.facebook.com/800397776713349/picture?type=normal '在chrome中可以正常使用。
The semicolon on this line is missing: 此行上的分号丢失:
String url = "https://graph.facebook.com/" + mate.getFacebookId() + "/picture?type=large"
It looks like you're using an invalid Facebook ID. 看来您使用的是无效的Facebook ID。 Check that mate.getFacebookId() is returning a valid ID.
检查mate.getFacebookId()是否返回有效的 ID。 When I use a valid ID, I'm able to return the image successfully inside an AsyncTask:
使用有效的ID时,我可以在AsyncTask中成功返回图像:
Use inside Main thread (onCreate, onActivityCreated, etc.): 在主线程内使用(onCreate,onActivityCreated等):
GetImage retrieve = new GetImage((ImageView)findViewById(R.id.yourimageview));
retrieve.execute();
GetImage: 的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.