0

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?

4

2 回答 2

1

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
}
于 2012-12-17T07:17:34.500 回答
0

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.

于 2012-12-17T05:52:25.850 回答