How to get email id From Android Facebook SDK 4.6.0?

前端 未结 3 843
野趣味
野趣味 2021-01-29 10:20

Here is my code for getting user information after facebook login. I am trying to get emailid from user I am getting Name , id , but not getting the emailid .I have tried with t

3条回答
  •  故里飘歌
    2021-01-29 10:43

    Starting with Graph API v2.4, you need to specifiy each field which you want to have returned in your query.

    new GraphRequest(AccessToken.getCurrentAccessToken(),
      "/me", null , HttpMethod.GET,
      new GraphRequest.Callback() {
        ...
    

    needs to become

    new GraphRequest(AccessToken.getCurrentAccessToken(),
      "/me?fields=id,name,email", null , HttpMethod.GET,
      new GraphRequest.Callback() {
        ...
    

    This is very well documented, and there are dozens of similar questions here on SO. Please refer to the docs first before posting a question.

    Keep in mind that you need the appropriate permissions to be able to request user details. In this case it's email

    See:

    • https://developers.facebook.com/docs/apps/changelog/#v2_4
    • https://developers.facebook.com/docs/facebook-login/permissions/v2.5

提交回复
热议问题