如何从Facebook API版本v2.4获取用户电子邮件和生日

时间:2015-07-22 05:51:26

标签: android facebook

我无法在API版本v2.4中获取facebook用户电子邮件。我在api version2.3中有一个应用程序,它返回用户的电子邮件和其他详细信息,但现在facebook将api版本更新为新应用程序。如果我使用像veriosn< = 2.3这样的旧应用程序,则使用以下代码返回用户电子邮件。但是在api版本2.4中,我无法收到电子邮件和出生日期。

GraphRequest.newMeRequest(result.getAccessToken(), new GraphRequest.GraphJSONObjectCallback()
    {
        @Override
        public void onCompleted(JSONObject me, GraphResponse response)
        {
            if (response.getError() != null)
            {
                // handle error
            }
            else
            {
                Log.e("",""+me.toString());
                Log.e("",""+response.getJSONObject().toString());

            }
        }
    }).executeAsync();

2 个答案:

答案 0 :(得分:1)

您必须明确定义要根据请求检索的字段,例如/me?fields=id,name,email,birthday而非/me

  

要尝试提高移动网络的性能,v2.4中的节点和边缘要求您明确请求GET请求所需的字段。例如,GET /v2.4/me/feed默认不再包含喜欢和评论,但GET /v2.4/me/feed?fields=comments,likes将返回数据。有关详细信息,请参阅有关如何请求特定字段的文档。

答案 1 :(得分:0)

从v2.4起,您需要在请求中包含您需要的字段。

GraphRequest request = GraphRequest.newMeRequest(
                     AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                          @Override
                          public void onCompleted(JSONObject userMe, GraphResponse response) {
                              if(userMe!=null){
                                 //...... do your things 

                              }
                          }
                }); 

Bundle parameters = new Bundle();

//Add the fields that you need, you dont forget add the right permission
  parameters.putString("fields","email,id,name,picture,birthday");
  request.setParameters(parameters);

//Now you can execute
             GraphRequest.executeBatchAsync(request);