Android的 - Facebook的GraphUser没有email属性 [英] Android - Facebook GraphUser has no email attribute

查看:284
本文介绍了Android的 - Facebook的GraphUser没有email属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查,并仔细检查有关问题的在线资源 - 但我仍然无法从Facebook的回应email属性。

作为入门指示,我实现了对LoginButton(basic_auth,电子邮件,user_birthday)的读取权限。创建一个会话(Session.createFromExistingAccessToken)时,也设置了相同的权限。然而,在回调函数,记录GraphUser和Response对象的时候,我还是没能获取用户的电子邮件。

什么是为什么错误仍坚持可能的原因是什么?我错过了一些步骤?

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

的Facebook会话类

  ...
    公共静态的ArrayList<串GT; getPermissions(){
       如果(PERMISSIONS.isEmpty()){
        PERMISSIONS.add(basic_info);
        PERMISSIONS.add(电子邮件);
        PERMISSIONS.add(publish_actions);
        PERMISSIONS.add(user_birthday);
       }
       返回的权限;
    }
...

WebDialog.onCompleteListener

 会议= Session.getActiveSession();如果(session.isOpened()及!&放大器;!session.isClosed()){
    Logger.log(Thread.currentThread()的getStackTrace(),称的accessToken+值,Log.DEBUG);
    在= AccessToken.createFromExistingAccessToken(values​​.getString(的access_token),NULL,NULL,AccessTokenSource.WEB_VIEW,FBSessionV2.getPermissions())的accessToken;
    会话= Session.openActiveSessionWithAccessToken(ControllerBase.getInstance()getActivity(),在,CB);
}其他{
    Logger.log(Thread.currentThread()的getStackTrace(),称openactivesession,Log.DEBUG);
    Session.openActiveSession(ControllerBase.getInstance()getActivity(),真实,CB);
}

GraphUserCallback()

  ...
    userProfile.put(facebookId,user.getId());
    userProfile.put(电子邮件,user.getProperty(电子邮件));
    userProfile.put(如first_name,user.getFirstName());
    userProfile.put(姓氏,user.getLastName());
    userProfile.put(名,user.getName());
    userProfile.put(性别,user.getProperty(性别));
    userProfile.put(生日,user.getBirthday());
    如果(user.getProperty(电子邮件)!= NULL){
        userProfile.put(电子邮件(字符串)user.getProperty(电子邮件));
    }
...

更新

好像我们只是遇到问题时,我们的Facebook应用程序试图登录Facebook账户,是不是一个开发商(可能还有是管理员)。我们只是试图登录在具有开发者角色我们FB账号之一 - 并且取得了成功。

不过,由于应用程序将供市民使用作出,这仍然没有解决我们的问题(可能也被视为创可贴修复现在 - 我还需要进一步调查该问题)

解决方案

也许你的应用程序在沙盒模式。请看看这里:

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

它说


  

请注意,如果您的应用程序在沙盒模式下,你不能调用任何
  API调用代表用户谁也看不到你的应用程序。


I've checked and double-checked online sources regarding the issue - but I still can't get the email attribute from the Facebook Response.

As indicated on the Getting Started, I implemented the read permissions ("basic_auth", "email", "user_birthday") on the LoginButton. Also set the same permissions when creating a session (Session.createFromExistingAccessToken). However, on the callback function, when Logging the GraphUser and Response object, I still wasn't able to retrieve the email of the user.

What are the possible reasons on why the error is still persisting? Am I missing some steps?

**onCreate()**

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

Facebook session class

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

UPDATE

It seems we're only having trouble when we're trying to log-in a Facebook account that is not a Developer (and may as well be Administrator) of the Facebook app. We just tried to log-in one of our FB account that has a Developer role - and it succeeds.

However, since the app will be made for public use, this still doesn't solve our problem (may as well be treated as a band-aid fix for now - I still need to further investigate the issue).

解决方案

Probably your app is in sandbox mode. Please have a look here:

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

It's saying

Please note that when your app is in Sandbox Mode, you cannot call any API calls on behalf of users who cannot see your app.

这篇关于Android的 - Facebook的GraphUser没有email属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆