Reputation: 9092
I've successfully logged into Facebook's OAuth system and retrieved my access token. I've stored the token in a cookie. Now I want to query the user's data.
Here's my problem. At this point I do not yet have the user's Id. It doesn't seem like I can do anything with the graph API unless I have the user's id.
What am I missing here?
Upvotes: 0
Views: 245
Reputation: 44609
a user need to be logged in your app in order for you to get his ID (the most basic permission).
For this, you can use the Javascript SDK, or you can link to a login page using the PHP SDK getLoginUrl
https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/
For anything related to a user on the OpenGraph or the Graph API, you at least need him to be logged into your app, and this mean you need to ask user basic permission. Until then, the user is completly anonymous to your app.
You can use the /me
alias to simplify requesting the Graph API, but you still need a valid access_token
provided by asking basic permissions. Until then, /me
or /{{id}}
will not return anything.
Upvotes: 0
Reputation: 9092
I found the solution.
I don't need the UserID as the graph api uses https://graph.facebook.com/me as an alias to to https://graph.facebook.com/USER_ID.
If you still need the user id, doing a GET request on
https://graph.facebook.com/me?fields=id
returns the current user's id with in JSON data as below.
{
"id": USER_ID
}
Upvotes: 1