gpt4 book ai didi

java - 尝试在 Android 中获取用户的 Facebook 个人资料图片时出现白色问号

转载 作者:行者123 更新时间:2023-12-01 11:42:06 25 4
gpt4 key购买 nike

我将 app-scoped-ids 存储在数据库中,希望通过图形 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();

获取图像:

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);
}

}

关于java - 尝试在 Android 中获取用户的 Facebook 个人资料图片时出现白色问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29442823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com