簡體   English   中英

如何在facebook SDK 3.0 Android中獲取用戶的facebook個人資料圖片

[英]How to get facebook profile picture of user in facebook SDK 3.0 Android

我正在使用facebook SDK 3.0我必須獲得用戶登錄的個人資料圖片。 這是我使用的代碼:

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

但我沒有得到理想的結果。

您應該更改以下代碼:

URL image_value = new URL("http://graph.facebook.com/"+id+"/picture" );

可以在此處找到URL的可能GET參數: https//developers.facebook.com/docs/graph-api/reference/user/picture/

使用https://而不是http://我遇到了同樣的問題。

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

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

請參閱此

只需在其上調用setProfileId(String profileId)

它將負責顯示圖像。

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

使用來自facebook sdk的ProfilePictureView

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

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

我希望它對你有所幫助。

嘗試這個..

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

一旦您的Facebook帳戶登錄到應用程序,只需執行以下操作:

String url = Profile.getCurrentProfile().getProfilePictureUri(x, y).toString();

x和y是寬度和高度。

請參閱doc: https//developers.facebook.com/docs/reference/android/current/class/Profile/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM