2013-05-04 187 views
15

我正在使用Facebook SDK 3.0我必須獲取用戶登錄的個人資料圖片。 這裏是我使用的代碼:如何在Facebook SDK 3.0中獲取facebook用戶的個人資料圖片Android

URL image_value = new URL("http://graph.facebook.com/"+id+"/picture"); 
profPict=BitmapFactory.decodeStream(image_value.openConnection().getInputStream()); 

但我沒有得到期望的結果。

+1

我也在尋找相同的,沒有得到使用相同的代碼:) – user 2013-05-04 09:15:15

回答

12

如果您嘗試在應用中顯示個人資料照片,請使用Facebook SDK中的ProfilePictureView

Refer This

只要打電話就可以了setProfileId(String profileId)

它會照顧顯示圖像。

+0

難道是解決問題的準確資料圖片? – 2013-05-12 22:09:26

+0

它是異步加載的嗎? – 2014-02-01 17:05:37

+0

是的,它加載圖像async-ly :) – 2014-02-01 19:10:14

2

你可以做這樣的事情一個線程中:

String url = "http://graph.facebook.com/"+id+"/picture"; 
HttpConnection conn = new HttpConnection(url); 
conn.openConnection(); 

Drawable d = Drawable.createFromStream(new BufferedInputStream(conn.getInputStream()), "image"); 

conn.close(); 

我希望它幫你。

5

使用ProfilePictureView

16

使用https://而不是http://我面臨同樣的問題。

URL image_value = new URL("https://graph.facebook.com/"+id+"/picture"); 
profPict = BitmapFactory.decodeStream(image_value.openConnection().getInputStream()); 
+1

謝謝!唯一有幫助的答案。 – Dima 2014-06-14 15:13:21

+0

我已經解決了與您的幫助相同的問題。謝謝。 – TeachMeJava 2015-02-05 23:35:48

6
String id = user.getId(); 
try { 
    URL url = new URL("http://graph.facebook.com/"+ id+ "/picture?type=large"); 
    String image_path = uri.toString(); 
    System.out.println("image::> " + image_path); 
} 
catch (MalformedURLException e) { 
    e.printStackTrace(); 
} 
2

試試這個..

try { 
     imageURL = new URL("https://graph.facebook.com/" + 
               id+ "/picture?type=large"); 
     Log.e("URL", imageURL.toString()); 
     } catch (MalformedURLException e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      try { 
        bitmap = BitmapFactory.decodeStream(imageURL 
           .openConnection().getInputStream()); 
       } catch (IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
       } 

     ProfileDp.setImageBitmap(bitmap);