2012-01-09 167 views
2

我正在使用以下代碼獲取使用Resfb的朋友的個人資料圖片。我也用名字id和圖像得到了迴應。請有人幫助我如何從這些數據中獲取圖像。從restfb獲取朋友個人資料圖片

代碼

Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class,Parameter.with("fields", "id, name,picture")); 

響應

"data":[{"id":"554603591","name":"Arjun Rao","picture":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-snc4\/211391_554603591_2022493_q.jpg"}" 

感謝

回答

0

您可以使用restfb來解析JSON對象:

JsonObject obj = new JsonObject(SERVER_RESPONSE); 
try { 
    String pictureURL = obj.getString("picture"); 
    } 
catch(JsonException e) { 
     // key 'picture' not found 
     e.printStackTrace(); 
} 
0

你知道如何解析響應?

如果是,只需獲取圖像的URL,打開URLConnection並執行getInputStream()(代碼爲in this SO answer)。

隨着InputStream,你可以保存到一個文件或發送給客戶端。

+1

考慮添加上下文的鏈接。有關詳細信息,請參見[如何回答](http://stackoverflow.com/questions/how-to-answer)。 – bytebuster 2012-10-20 01:22:10

+0

我認爲這是一個很好的答案。我不是在這裏來判斷它是對還是錯,但在質量方面,它看起來很好。 – Zizouz212 2016-02-18 23:25:10

0

難道說RestFB是不是最新的感覺如何圖形API返回(一些對象)裏面的「數據」對象?

我設法到各地工作,這個自定義類:

public class DataPictureHolder { 
    @Facebook("data") 
    public ProfilePictureSource picture; 
} 
相關問題