繁体   English   中英

从Facebook获取电子邮件和生日

[英]Get email and birthday from facebook

如果帐户已注册多个电子邮件,如何从Facebook获取主要电子邮件?

我的登录按钮有以下方法:

private void onClickLogin() {
        session = Session.getActiveSession();
        if (!session.isOpened() && !session.isClosed()) {
            session.openForRead(new Session.OpenRequest(this).setPermissions(Arrays.asList("public_profile", "email")).setCallback(statusCallback));
        } else {
            Session.openActiveSession(this, true, statusCallback);
        }
    }

单击此方法可获得详细信息:

public void onClick(View v) {
        session = Session.getActiveSession();
        if (session == null) {
            Toast.makeText(HelloFacebookSampleActivity.this, "NULL NULL NULL NIGGA NULL!!", Toast.LENGTH_SHORT).show();
        } else {
            Request.newMeRequest(session, new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                        Toast.makeText(HelloFacebookSampleActivity.this, buildUserInfoDisplay(user), Toast.LENGTH_SHORT).show();
                    }
                    }
                }).executeAsync();
            }
        }

这是buildUserInfoDisplay方法:

private String buildUserInfoDisplay(GraphUser user) {
    StringBuilder userInfo = new StringBuilder("");
    userInfo.append(String.format("First Name: %s\n\n", user.getFirstName()));
    userInfo.append(String.format("Last Name: %s\n\n", user.getLastName()));
    userInfo.append(String.format("Birthday: %s\n\n", user.getBirthday()));
    userInfo.append(String.format("Email1: %s\n\n", (String) user.getProperty("email")));
    userInfo.append(String.format("Email2: %s\n\n", user.getProperty("email")));
    userInfo.append(String.format("Locale: %s\n\n", user.getProperty("locale")));
    return userInfo.toString();
}

我得到名字和姓氏,以及语言环境正确,但是我没有电子邮件和生日。

不知道我做错了什么。 谢谢。

回答:

因此答案只是重新安装该应用程序。 -_-

该API仅在电子邮件字段中返回一个电子邮件地址,这将是主要电子邮件。 如果用户有多封电子邮件,则仅返回主电子邮件。 如果没有主电子邮件,或者没有经过验证,则不返回该字段。 请注意,您的应用还必须具有电子邮件权限。

请参阅https://developers.facebook.com/docs/graph-api/reference/v2.0/user中的文档

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM