![](/img/trans.png)
[英]getting exceptions when loading facebook profile picture in android with facebook sdk 4+
[英]Getting Facebook Profile Picture in Android
我正在構建一個Android應用程序,並已成功集成Facebook登錄作為注冊和登錄的唯一形式。 我正在嘗試找出獲取用戶個人資料圖片的最佳方法,我已經在開發人員文檔中允許使用-https: //developers.facebook.com/docs/graph-api/reference/user/picture/ ,但是我我不確定如何處理響應,也就是說我實際上是如何在響應中獲取圖像的,它是通過位圖發送還是作為URL鏈接發送,我不太確定。
這是文檔提供的用於獲取個人資料圖片的代碼
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{user-id}/picture",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
謝謝您的幫助
您必須像Docs所說的那樣執行GraphRequest,但這是您的方式。 在您的XML布局中使用Facebook的ProfilePictureView
。
XML布局
<com.facebook.login.widget.ProfilePictureView
android:id="@+id/myProfilePic"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"/>
活動/片段代碼
ProfilePictureView profilePic = (ProfilePictureView) dialogView.findViewById(R.id.myProfilePic);
GraphRequestAsyncTask request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (user != null) {
// set the profile picture using their Facebook ID
profilePic.setProfileId(user.optString("id"));
}
}
}).executeAsync();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.