Android Facebook集成获取电子邮件



我根据教程将Facebook登录到我的应用程序中,但是我找不到有关如何检索用户电子邮件地址的任何好信息。电子邮件确实是我唯一需要的东西。我能够获得其他基本信息。我的活动扩展了FacebookActivity。当用户单击登录我的应用时,我致电:

this.openSession();

然后我有:

@Override
    protected void onSessionStateChange(SessionState state, Exception exception) 
    {
          // user has either logged in or not ...
          if (state.isOpened()) 
          {
                // make request to the /me API
                Request request = Request.newMeRequest(
                  this.getSession(),
                  new Request.GraphUserCallback() 
                  {
                        // callback after Graph API response with user object
                        @Override
                        public void onCompleted(GraphUser user, Response response) 
                        {
                          if (user != null) 
                          {  
                            TextView welcome = (TextView) findViewById(R.id.welcome);
                            welcome.setText("Hello " + user.getName() + "!");
                            Log.d("user fname",user.getFirstName());
                            Log.d("user lname",user.getLastName());
                            Log.d("user username",user.getUsername());
                            Log.d("user email",(String)user.getProperty("email"));
                      }
                    }
              }
            );
                Request.executeBatchAsync(request);
          }
    }

Graphuser不会公开电子邮件。有什么想法吗?

我已经在Facebook开发面板中设置了"电子邮件"权限。

用于新的Facebook SDK 3.0

String email = (String) response.getGraphObject().getProperty("email");

好吧,我弄清楚了。Graphuser对象将包含电子邮件地址,但我找到了一个教程,该教程与基本教程完全不同。

这是基本教程:https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

,这是您除了基本教程之外必须实现的教程,以使其正常工作:https://developers.facebook.com/docs/howtos/androidsdk/3.0/login-with-facebook/#step3

您要做的就是实现第一个登录样本,然后将其更改为第二个样本,然后使用最终产品中的第一个样本的一部分。如果您从我发布的第一个教程开始仔细浏览每个教程,则可以通过实现其他许可请求来捕获用户所需的任何数据。

希望这对别人有帮助。我在" so"上搜索的所有问题都用过时的方法指的是旧的API。

对于更多权限,您可以更改.opensession()函数为.opensessionForread(字符串appid,list< string> perstry> perstrys),如果您在strings.xml run.xml run .opensessionforread(null,null,,null,,,,,,,,,,,,地)列表权限)

最新更新