2014-03-26 110 views
14

在我的應用程序中,我使用Picasso library從網址加載圖像。 這是一個很好的工作可輕鬆導入和可用的圖書館,只是做我需要的東西。畢加索圖書館今天停止與facebook圖片鏈接工作

但是,今天它停止工作,而不是在開發它時停止在編譯的apk上工作。

所以我找啊找的原因後,我才發現這車的事情:

我使用Facebook的網址圖形加載個人資料照片。

這裏是一個這樣的: profile pictre

鏈接其實是 「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

當然,這兩個網址的要求在瀏覽器中工作,你可以看到個人資料圖片。

然而,當我測試兩個環節與畢加索:

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

所以得出的結論是,臉譜可能改變的東西,從現在開始,畢加索無法從圖中載入圖像。

有人可以建議我做一些工作嗎? 當然,我可以嘗試不同的圖書館,但如果有其他方式,我會很高興。

+3

這發生在我們身上了。一切都很好,直到昨天晚些時候。我們沒有使用畢加索,只是Facebook SDK。無論哪種方式,我們只是加載圖片形式的URL,所以它絕對不是圖書館的問題。 Facebook方面似乎有所改變。他們總是用來重定向到那個fbcdn。仍在尋找解決方案。讓我們張貼。謝謝 – Bach

+0

好吧,看到它不僅僅是爲了我,儘管我爲你們感到自豪。當我弄清楚什麼時,我會編輯,謝謝你的評論! –

回答

42

Workaround1:

更改爲HTTPS從http。

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

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

Workaround2:

this話題找到soulution。

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

該資料圖片,你可以使用:

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

它返回一個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 
     } 
    } 
} 

和多田!它是。網址的關鍵是您可以用來加載圖片的重定向網址。

(這將需要的OAuth這我沒有測試過,只是Workaround1棒)

+3

解決方法3:使用[OkHttp](http://square.github.io/okhttp),它將遵循從HTTP到HTTPS的重定向。 –

+0

這兩個變通辦法並沒有爲我工作:(它注意到的問題只發生在Android 5.1.1 Moto X.沒有在其他設備上測試過,但所有我的Android 5.1.1有這個問題 –

4

試試這個。工作對我來說完全

相關性:編譯 '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); 
+2

這幫了我: ) –

+0

在我的情況下,我不得不使用修改的OkHttpDownloader來使它工作(編譯'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2')。如下所示:https://stackoverflow.com/a/38715078/4240534 – goemic