![](/img/trans.png)
[英]White question mark while trying to get user's Facebook profile picture in Android
[英]How do I get the user's name, email, and profile picture when the user logs in with their Facebook account?
我已經能夠在我的android應用程序上使用用戶的Facebook帳戶創建成功的登錄名。 現在,我希望能夠獲得用戶的姓名,電子郵件和個人資料圖片。
與用戶使用其Google帳戶登錄時的操作類似:
GoogleSignInAccount account = result.getSignInAccount();
String name = account.getDisplayName();
String email = account.getEmail();
String img_url = account.getPhotoUrl().toString();
Name.setText(name);
Username.setText(email);
Glide.with(this).load(img_url).into(Prof_Pic);
上面的代碼顯示了用戶使用其Google帳戶登錄時的操作。 當用戶使用其Facebook帳戶登錄時,我幾乎想做同樣的事情。 我該怎么辦?
在獲得用戶facebook accessToken之后使用它:
public static void getFacebookUserInfo(AccessToken accessToken,
GraphRequest.GraphJSONObjectCallback callback) {
if (accessToken == null) {
throw new NullPointerException("AccessToken should not be null !");
}
Bundle params = new Bundle();
params.putString("fields", "name, email");
GraphRequest request = GraphRequest.newMeRequest(accessToken, loginCallback);
request.setParameters(params);
request.executeAsync();
}
和回調:
private class FacebookUserInfoCallback implements GraphRequest.GraphJSONObjectCallback {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if (response.getError() == null) {
String name = object.optString("name");
String email = object.optString("email");
}
}
}
並獲取個人資料圖片(Facebook用戶登錄后應調用):
Profile profile = Profile.getCurrentProfile();
if(profile != null) {
Uri profilePictureUri = profile.getProfilePictureUri(width, height);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.