简体   繁体   English

当用户使用其Facebook帐户登录时,如何获取用户的姓名,电子邮件和个人资料图片?

[英]How do I get the user's name, email, and profile picture when the user logs in with their Facebook account?

I have been able to create a successful login with the user's Facebook account on my android app. 我已经能够在我的android应用程序上使用用户的Facebook帐户创建成功的登录名。 Now, I want to be able to get the user's name, email, and profile picture. 现在,我希望能够获得用户的姓名,电子邮件和个人资料图片。

Similar to what I did when the user logs in with their Google account: 与用户使用其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);

The above code shows what I did when the user logged in with their Google account. 上面的代码显示了用户使用其Google帐户登录时的操作。 I want to pretty much do the same thing when the user logs in with their Facebook account. 当用户使用其Facebook帐户登录时,我几乎想做同样的事情。 What do I do? 我该怎么办?

Use this after you get the user facebook accessToken : 在获得用户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();
} 

and the callback : 和回调:

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

and get the profile picture(should be call after facebook user logged in) : 并获取个人资料图片(Facebook用户登录后应调用):

Profile profile = Profile.getCurrentProfile();
if(profile != null) {
    Uri profilePictureUri = profile.getProfilePictureUri(width, height);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在Android中获取用户的Facebook个人资料图片时出现白色问号 - White question mark while trying to get user's Facebook profile picture in Android 在Android应用中检索Facebook用户的个人资料图片时为空指针 - Null pointer when retrieving a Facebook user's profile picture in Android app 如何使用 android Studio 在 firebase 的登录用户上添加用户的全名和头像 - How to add user's full name and profile picture on logined user of firebase using android Studio 如何使用uId在Facebook中登录用户的信息,例如电子邮件ID,名称,城市等 - How I can get logged in user's info like email id,name,city etc. in Facebook with uId 如何在Liferay上获得用户的名字? - how do I get the user's first name on Liferay? 如何获取Gmail帐户的个人资料图片 - How to get profile picture of gmail account 如何从Java解锁Oracle用户的帐户? - How do I unlock an Oracle user's account from Java? 无法从Facebook获取用户的个人资料图片。 请查看详细信息 - Unable to fetch user's profile picture from facebook. Please see details 如何从Facebook获取身份验证用户,以及如何从Java中的图api获取配置文件数据 - how get authenticate user from facebook and how i get Profile data from graph api in java 为什么登录Facebook帐户时用户电子邮件为空,但登录Google帐户时为什么不为空? - Why is user email null when signing into Facebook account, but not null when signing into Google account?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM