简体   繁体   中英

How to get a user email from Facebook Graph Api?

I'm confused here,

I'm trying to get user data using Facebook Api, I'm requesting email permission using scope=email like this:

https://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&redirect_uri=MY_URI&scope=email

In Facebook access confirmation window I see that my application requests access to the email, but even after that when I do request to Graph Api it doesn't return the email (it does return all other fields) If I do a request like this:

https://graph.facebook.com/me?fields=id,name,email&access_token=MY_TOKEN

it only returns id and name.

Thank you all guys for your time. It started to work by itself after I deleted the app access from My account in Facebook and then tried to get access again.

Check whether you have the permission of email or user have unchecked it while approving the request you raised from the URL : facebook.com/dialog/oauth?client_id=MY_APP_ID&redirect_uri=MY_URI&scope=email. You can check using https://graph.facebook.com/me?fields=permissions&access_token=[TOKEN] . It should give you response notifying whether email permission is granted or not like below:

{
    "permissions":{
        "data": [
        {
            "permission": "user_friends",
            "status": "granted"
         },
         {
            "permission": "email",
            "status": "granted"
         },
         {
            "permission": "public_profile",
            "status": "granted"
         }
      ]
   },
   "id": "10207905751235096"
}

check facebook tool explorer for more: https://developers.facebook.com/tools/explorer/

I'm not sure if this is for an app, if so, I had the same problem until I published my app. Check the documentation to see if it applies to you:

https://developers.facebook.com/apps/ {your app id}/review-status/

After approved, the email and other sensitive info will show...

Try using c# sdk it's to easy with it. There are some examples in this link .

Hope it helps.

Use the FQL API for this:

query:

select contact_email from user where uid=me()

Call:

https://api.facebook.com/method/fql.query?format=json&query=select+contact_email+from+user+where+uid%3Dme%28%29&access_token=[access_token]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM