14

在我的应用程序中,我使用Picasso 库从 url 加载图像。它是一个运行良好且易于导入和使用的库,只需做我需要的事情。

然而,今天它停止了工作,而不是在开发时它停止在编译的 apk 上工作。

所以在我搜索并搜索了我刚刚发现这个错误的原因之后:

我使用 facebook 图表 url 加载个人资料图片。

这是一个像: 个人资料图片

该链接实际上是“ http://graph.facebook.com/1464090949/picture?type=large

但它正在重定向到: https ://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg

当然,这两个 url 调用都在浏览器中工作,您可以看到个人资料图片。

但是,当我用毕加索测试两个链接时:

    ImageView iv = (ImageView)findViewById(R.id.imageView1);

    //Url1 NOT working, loads nothing.
    String url1 = "http://graph.facebook.com/1464090949/picture?type=large";

    //Url2 is the same as URL1, i just copied it from a browser, and this is working
    String url2 = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg";


    Picasso.with(this).load(url2).into(iv);

所以结论是,facebook 可能改变了一些东西,从现在开始,毕加索不能从图表中加载图像。

任何人都可以建议我做这件事吗?当然,我可以尝试不同的库,但如果有其他方式,我会非常高兴。

4

3 回答 3

43

解决方法1:

从 http更改为https 。

工作: https ://graph.facebook.com/1464090949/picture?type=large

不工作: http ://graph.facebook.com/1464090949/picture?type=large

解决方法2:

找到关于这个主题的解决方案。

如果你想例如: http ://graph.facebook.com/1464090949/picture?type=large

您可以使用此个人资料图片:

https://graph.facebook.com/1464090949/?fields=picture.type(大)

它返回一个 JSON 对象:

   {
   "id": "1464090949",
   "picture": {
      "data": {
         "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg",
         "is_silhouette": false
      }
   }
}

还有多田!它在那里。url 的键是可用于加载图像的重定向 url。

(这将需要我没有测试过的 oAuth,坚持使用 Workaround1)

于 2014-03-27T11:06:27.613 回答
5

尝试这个。完美地为我工作

依赖:编译'com.squareup.okhttp:okhttp:2.5.0'

Picasso.Builder builder = new Picasso.Builder(mContext);
        builder.listener(new Picasso.Listener() {
            @Override
            public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
                /*holder.getIvSpeakerPicture()
                        .setImageDrawable(context.getResources()
                                .getDrawable("your drawable id"));*/
            }
        });
        builder.downloader(new OkHttpDownloader(mContext));
        builder.build().load(image).into(viewHolder.image);
于 2017-03-19T14:51:40.683 回答
0

如果您像我一样使用 Amazon AWS CloudFront,您可以访问此页面以获取 Amazon 提供的有关如何设置 URL 转发的详细说明。

至少,为了让 Picasso 使用您的重定向 URL,您的 URL 必须支持 https。那是。https://yourdomain.com应该重定向到https://yourAWScloudfrontdomain.net

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/SecureConnections.html#CNAMEsAndHTTPS

于 2015-08-29T12:15:02.147 回答