【问题标题】:Android - Facebook GraphUser has no email attributeAndroid - Facebook GraphUser 没有电子邮件属性
【发布时间】:2014-02-17 09:03:52
【问题描述】:

我已经检查并仔细检查了有关该问题的在线资源 - 但我仍然无法从 Facebook 响应中获取电子邮件属性。

如入门中所述,我在 LoginButton 上实现了读取权限(“basic_auth”、“email”、“user_birthday”)。创建会话时也设置相同的权限(Session.createFromExistingAccessToken)。但是,在回调函数上,当 Logging GraphUser 和 Response 对象时,我仍然无法检索到用户的电子邮件。

错误仍然存​​在的可能原因是什么?我错过了一些步骤吗?

**onCreate()**

    ((LoginButton) findViewById(R.id.dialog_generic_footer_button_fblogin))
                .setPublishPermissions(FBSessionV2.getPermissions());

Facebook 会话类

...
    public static ArrayList<String> getPermissions(){
       if (PERMISSIONS.isEmpty()){
        PERMISSIONS.add("basic_info");
        PERMISSIONS.add("email");
        PERMISSIONS.add("publish_actions");
        PERMISSIONS.add("user_birthday");
       }
       return PERMISSIONS;
    }
...

WebDialog.onCompleteListener

session = Session.getActiveSession();

if (!session.isOpened() && !session.isClosed()){
    Logger.log(Thread.currentThread().getStackTrace(), "calling accesstoken" + values, Log.DEBUG);
    AccessToken at = AccessToken.createFromExistingAccessToken(values.getString("access_token"), null, null, AccessTokenSource.WEB_VIEW, FBSessionV2.getPermissions());
    session = Session.openActiveSessionWithAccessToken(ControllerBase.getInstance().getActivity(), at, cb);
} else {
    Logger.log(Thread.currentThread().getStackTrace(), "calling openactivesession", Log.DEBUG);
    Session.openActiveSession(ControllerBase.getInstance().getActivity(), true, cb);
}

GraphUserCallback()

...
    userProfile.put("facebookId", user.getId());
    userProfile.put("email", user.getProperty("email"));
    userProfile.put("first_name", user.getFirstName());
    userProfile.put("last_name", user.getLastName());
    userProfile.put("name", user.getName());
    userProfile.put("gender", user.getProperty("gender"));
    userProfile.put("birthday", user.getBirthday());
    if (user.getProperty("email") != null){
        userProfile.put("email", (String) user.getProperty("email"));
    }
...

更新

我们似乎只是在尝试登录不是 Facebook 应用程序开发人员(也可能是管理员)的 Facebook 帐户时遇到问题。我们刚刚尝试登录一个具有开发者角色的 FB 帐户 - 并且成功了。

但是,由于该应用程序将供公众使用,因此这仍然不能解决我们的问题(现在还不如将其视为创可贴修复 - 我仍需要进一步调查该问题)。

【问题讨论】:

  • 试试下面的解决方案,让我知道它是否有效......

标签: android facebook email


【解决方案1】:

试试这种方式,

String email = user.asMap().get("email").toString();

然后你可以传递这个字符串参数来打印电子邮件

TextView mEmail = (TextView) findViewById(R.id.email);
mEmail.setText(email);

通过这种方式,我可以成功获取 email-id。

【讨论】:

  • 您好!我已经尝试过了,遗憾的是它仍然无法正常工作,当我记录它时,用户对象本身没有任何电子邮件属性 - 因此,在 .get("email") 上获得了一个空值。
  • 但我使用的是上面相同的代码,并且我也收到了用户的电子邮件。你能发布你的整个代码吗?
  • 根据要求,这是我实现的整个单例类。 pastie.org/private/75jh534uics5zvxdfs9tzw。还有其他因素导致我无法获得电子邮件属性吗?比如之前的session清除、facebook账号年龄、facebook app配置等?
  • 赞成答案,因为它确实是检索电子邮件属性的一种方法。但是由于一些奇怪的事件,公共 FB 帐户仍然无法获取电子邮件属性。 显然我还不能投票 :)
  • 您的应用是否处于沙盒模式?
【解决方案2】:

您的应用可能处于沙盒模式。请看这里:

https://developers.facebook.com/docs/ApplicationSecurity/#sandbox

这是说

请注意,当您的应用处于沙盒模式时,您无法调用任何 代表无法看到您的应用的用户调用 API。

【讨论】:

  • 您好!我刚刚在应用程序页面上进行了检查,没有 - 应用程序不在沙盒模式下。在状态和评论页面中,“您想让这个应用程序及其所有实时功能向公众开放吗?”设置为是
猜你喜欢
  • 2015-11-17
  • 2015-10-18
  • 2014-07-27
  • 1970-01-01
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-08
相关资源
最近更新 更多