【问题标题】:Facebook avatar failed to download using Picasso in AndroidFacebook 头像无法在 Android 中使用 Picasso 下载
【发布时间】:2014-05-09 09:33:18
【问题描述】:

您好,我正在尝试将 Picasso 库集成到 android 中。这是我在 Picasso 的 load 方法中传递的 URL。

网址:http://graph.facebook.com/244054592454345/picture?type=large

Picasso onBitmapFailed 方法回调正在调用,这意味着它无法下载位图并将可绘制值设为空。

com.squareup.picasso.Target target = new com.squareup.picasso.Target() {

@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom loadedFrom) {
    userProfile.setBitmap(bitmap);
    // call the Web API to register the walker here
    new AudioStreetAsyncTask(getActivity(), userProfile, getString(R.string.registration_processing_message), new TaskCompleteListener() {
        @Override
        public void onTaskCompleted(String jsonResponse) {
           Log.d(TAG, jsonResponse);
        }
    });
}

@Override
public void onBitmapFailed(Drawable drawable) {
    userProfile.setBitmap(null);
    // call the Web API to register the walker here
    new AudioStreetAsyncTask(getActivity(), userProfile, getString(R.string.registration_processing_message), new TaskCompleteListener() {
        @Override
        public void onTaskCompleted(String jsonResponse) {
           Log.d(TAG, jsonResponse);
        }
    }).execute();
}

@Override
public void onPrepareLoad(Drawable drawable) {}
};

Picasso.with(getActivity()).load(imgUrl.toString()).into(target);

即使您可以看到 URL 正确但每次都失败,我也无法追踪它失败的原因。有什么想法吗?

【问题讨论】:

标签: android bitmap picasso


【解决方案1】:

正如@Jake Wharton 所说,它正在从 HTTP 重定向到 HTTPS,而您的客户端可能不是 妥善处理。使用 HTTPS 请求该 URL,以便重定向 保持相同的协议或将 OkHttp 放入您的应用程序(它将遵循 跨协议重定向)。

所以要么将你的 http 协议更新为 https,它应该可以工作。

或者你也可以调用这个 Web API 到https://graph.facebook.com/244054592454345/?fields=picture.type(large)

那么你会得到这个 JSON

{
   "picture": {
      "data": {
         "is_silhouette": false,
         "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t1.0-1/s200x200/1472865_191408954385576_14109897_n.jpg"
      }
   },
   "id": "244054592454345"
}

然后从这个 JSON 中获取 URL,然后使用这个 URL 来获取这个用户的 Facebook 头像。

Picasso.with(getActivity()).load("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t1.0-1/s200x200/1472865_191408954385576_14109897_n.jpg").into(target);

【讨论】:

猜你喜欢
  • 2016-07-01
  • 2019-08-14
  • 2016-12-18
  • 1970-01-01
  • 2020-01-09
  • 1970-01-01
  • 1970-01-01
  • 2020-03-18
  • 2013-01-12
相关资源
最近更新 更多