Error getting User data from Facebook - facebook

The login flow is working, I get a valid access token and everything. But when I retrieve the user data, I only get the name and userID. No email or other info from the public profile.
If I run a /me/permissions it returns granted on both email and public_profile. If I use facebook's Debug Tool with the access token it tells me the correct scope: email,public_profile.
So why am I not being able to get the data? I can't finish the signup process without it.
Any ideas?

As of Graph API 2.4, it no more returns several fields, you should explicitly ask for fields you want. See Graph API Changelog
Please read Graph API docs, especially this part about choosing fields

Related

How does facebook token works?

I want to write a process which downloads data about my ads.
Basically this is the code:
https://github.com/airflow-plugins/facebook_ads_plugin/blob/master/hooks/facebook_ads_hook.py
It construct a URI as:
https://graph.facebook.com/v{api_version}/act_{account_id}/insights?{payload}
Where payload contains the access_token, breakdowns, fields etc..
Now, I passed over the facebook dev guide https://developers.facebook.com/docs/graph-api/using-graph-api/ and it doesn't explain how do I get the account_id and the token.
It always leads to a user account that needs to log-in to facebook and then process the request.
I want to build a process that doesn't involve user action. Just download logs about my ads.
How can I do that? Where can I get the account_id and the token.
In other systems like google and other they create a json file with credentials that is used for the outh. there doesn't seem to be equivalent with facebook.
For this type of use case, I would create a System User that is permissioned on all your ad accounts, following this guide. That will allow you to generate a token that can used without user login. (You can do the same for your personal facebook account, but that requires you to pass app verification. This can be done without that.)
Then to get the account ids of all the accounts the system user is permissioned on, query the "me/adaccounts" endpoint, using the access token generated for the system user. The docs for that are here. You can use that to get a list of all the account ids.
Alternatively, if you only need one account id, you can get that straight from the facebook ads manager.

Suggestions on a website that uses Facebook's Graph API

I'm trying to build a website with the following requirements. I need help to see if it's possible at all. This website has a regular login (not Facebook). Upon being logged in, the user has the option to "attach" his facebook account. At this point I save the return user id in the DB. Then, I tried on another computer the following Facebook Graph API call with this user id but it said:
Fatal error: Uncaught GraphMethodException: You can only access the "home" connection for the current user. thrown in /home/public/vendor/facebook/php-sdk/src/base_facebook.php on line 1294
The call:
/{user-id}/home
Appreciate help.
According to the error message you're trying to call /{user-id}/home but are using an access token from a different user -
You can't fetch another user's news feed, only the current user of your app, using their access token
Try {user-id}/feed. If you are not using the accessToken that was generated by the facebook API on the "attach" time, you will be able to get only the public feeds/data. Using the access token that was generated at the "attach" time, you will be able to get data for your app permissions.
About access token
https://developers.facebook.com/docs/facebook-login/access-tokens
How to use the graph api
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0

Fetching facebook event feeds using graph api

I was able to fetch facebook events through my code until couple of days back and it used to return me proper JSON data with all the requested fields.
Suddenly i am trying to do it today again and i get only id value and nothing else. Any idea what went wrong.
http://graph.facebook.com/userid?limit=20&fields=events.fields(description,end_time,location,name,ticket_uri,venue)&access_token=access_token
is the request url format i am using.
You must use https:// when passing an access token.
Possibly, your access token don't let you fetch those details since you have not authorized your app to fetch user_events. You can check the access token here.
So, you have to check whether the user have authorized your app for this action or not before making this query. You can also fetch the permissions that user has granted at any time using-
/me/permissions

Possible bug with test users and page access tokens

Possible Facebook bug: First I am posting here because for some reason the button to create a bug never appears when I go to https://developers.facebook.com/bugs !
Facebook test users don't behave exactly like real users: If you make a call to graph api fql using a page access token to retrieve basic info for the user like name etc the api returns nothing. The reason why I am using a page access token is because I am making a batch request which requires the page access token. Real users users return the basic info like name with the page access token but test user don't.
Thanks

Facebook Connect Graph API - Why Can't I Retrieve All User's Details?

I feel like every second question i ask here is relating to Facebook Connect - that says a lot about their API. Anyway, that's politics, i digress..
I'm trying to pull back user details from the Graph API for use in my application (which is an FBML external website - JavaScript SDK for authentication).
I have requested the following permissions from the user: (using the regular dialog)
publish_stream
email
This works, and allows me to post to the user's wall, and grab their email from the Graph API.
But when i do a HTTP GET Request to the following URL:
https://graph.facebook.com/uid?access_token=oat (where uid = the user id of the user i'm attempting to grab details for, and oat = the OAuth token i have).
All that comes back in the JSON is the User ID (which i already have, since im putting it in the URL), and the email.
Why can i not get things like first name, last name, locale, etc?
Am i using the wrong URL? Is my OAuth token wrong?
I'm getting the OAuth token from here:
https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=myappid&client_secret=myappsecret
UPDATE:
It looks like the issue is my OAuth token.
Because when i go to the docs: http://developers.facebook.com/docs/api
And use the sample OAuth Token for the user im trying to retrieve, it gets all the details.
Anyone know what is wrong with my OAuth token call?
So, i was using the wrong URL for the OAuth Exchange. It needed to be this:
https://graph.facebook.com/oauth/exchange_sessions?type=client_cred&client_id=myappid&client_secrete=myappsecret&sessions=userseshid
The URL that i WAS using was as per the doco, the above one that works is nowhere to be found.
I'm at the point with FBC that i no longer care about the how, if it works, be thankful that it does even that and move on.
EDIT:
Also, i was wondering why the Graph API calls would "stop" working for no reason.
The answer is i needed to compare the Session Key used to obtain the OAuth token, with the Session Key currently in the cookies. If they are different, i needed to get a new OAuth token.
The session key used for any OAuth token is part of the actual OAuth token:
aaa|bbbb|cccc
Where bbbb is the session key. So i just compare that before doing any Graph API calls.