Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picasso library stopped working today with facebook graph picture links

In my app i use Picasso library to load images from urls. It is a nicely working easily importable and usable library, and just do the thing i need.

However, today it stopped working, and not while developping it is stopped working on a compiled apk.

So after i searched and searched for the reason i just found this buggy thing:

I use facebook graph urls to load profile pictures.

Here is one like: profile pictre,

the link is actually "http://graph.facebook.com/1464090949/picture?type=large"

But it is redirecting to: https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg

Of course, both of url calls working in a browser, and you can see the profile picture.

However when i test both links with Picasso:

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

So the conclusion is, facebook maybe changed something and from now on Picasso cannot load images from graph.

Anybody can suggest me something to make this work? Of course i can try different libraries but if there is an other way i would be really happy.

like image 337
Adam Varhegyi Avatar asked Mar 26 '14 22:03

Adam Varhegyi


People also ask

What is Picasso library for Android?

It is among the powerful image download and caching library for Android. Picasso simplifies the process of loading images from external URLs and displays them on your application. For example, downloading an image from the server is one of the most common tasks in any application.

What does the error placeholder image in Picasso mean?

Picasso will try to download the remote image three times and display the error placeholder image if it was unable to fetch the remote asset. The error image will be shown, in this case when there is no internet connectivity for the application. Instead of loading the image from the URL, the Picasso library shows the error image.

How do I use Picasso to fetch a remote image?

Here we are using Picasso to fetch a remote image and resize it before displaying it in an ImageView. If your application relies on remote assets, then it’s important to add a fallback in the form of a placeholder image. The placeholder image is shown immediately and replaced by the remote image when Picasso has finished fetching it.

How do I fix the size of an imageview in Picasso?

For any given Picasso call, we can fix this by one or more of the following approaches: Add an explicit width or height to the ImageView by setting layout_width=500dp in the layout file and then be sure to call fit () during your load: Picasso.with (…).load (imageUri).fit ().into (…)


2 Answers

Workaround1:

Change to https from http.

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

Not Working: http://graph.facebook.com/1464090949/picture?type=large

Workaround2:

Found soulution on this topic.

If you want for example: http://graph.facebook.com/1464090949/picture?type=large

This profile picture you could use:

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

Which returns a JSON Object:

   {
   "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
      }
   }
}

And tada! There it is. url's key is the redirected url you can use to load your images.

(This will need oAuth which i didnt tested, just stick with Workaround1)

like image 198
Adam Varhegyi Avatar answered Oct 18 '22 21:10

Adam Varhegyi


Try this. worked for me perfectly

Dependency: compile '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);
like image 45
Shubham Goel Avatar answered Oct 18 '22 22:10

Shubham Goel