Graph API Basics: Starting with the User Profile
Learn how to access a user profile with a long-lived access token.
The /me
endpoint
The /me
endpoint is an excellent starting point for using the Facebook Graph API. Through this endpoint, we will be able to retrieve basic user profile data belonging to our Facebook user.
In our last lesson, you took the short-lived user access token associated with one of your test users and exchanged it for a long-lived token. Now, we will use that long-lived token to make requests to the /me
endpoint. User-related endpoints on the Facebook Graph API start with /{user-id}
. But since you are using a user access token associated with a specific user, the /me
endpoint is just a shortcut/alias to the /{user-id}
endpoint for that user’s ID.
Let’s send a basic request to the /me
endpoint, including the access_token
as a query parameter. In the previous lesson, we already updated ACCESS_TOKEN to the value of the long-lived access token. Now, just click on Run below:
curl -X GET "https://graph.facebook.com/v10.0/me?\access_token={{ACCESS_TOKEN}}\" | json_pp
As a result, you should see some output with the name and Facebook ID for this test user. Success!
There are a few things that we should point out about what just happened here.
First, notice that we did not provide our Facebook App ID or App Secret when making this request. All we provided was the access token. Do you remember the illustration of the backstreet concert pass that we discussed a few lessons ago? It should be rephrased as: “As long as you can demonstrate that you have the authorization — and you do that by presenting an access token — Facebook does not care about authentication.”
Second, we saw that the /me
endpoint returned to us the Facebook ID and name associated with this user. But that’s a bit strange, considering the documentation for the User endpoint shows that there are so many more data fields associated with a User. How do we get more information than just the ID and name?
The answer is the ...