Fabien R
Fabien R

Reputation: 685

querying the graph api with curl

I want to check how to handle the access_token. So, I use curl to perform the following queries:

curl -X POST https://graph.facebook.com/oauth/access_token -d "client_id=<appId>&client_secret=<secret>&grant_type=client_credentials&redirect_uri="

It returns a value for access_token.

Then, I'd like to get the list of my friends:

curl -X POST https://graph.facebook.com/me/friends -d "access_token=<token>"

It returns this error:

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

Any hints ?

Upvotes: 8

Views: 18857

Answers (4)

Sreejith S
Sreejith S

Reputation: 1

You should enclose the "https://...." , with double quote after curl -X POST.

Upvotes: 0

anquegi
anquegi

Reputation: 11522

The easy way is to use graph API explorer, go there and get and acces token with your facebook developer account:

Generate a Basic User Access Token

When you get to building your own app, you'll need to learn about access tokens and how to generate them using Facebook Login, but for now, we can get one really quickly through the Graph API Explorer:

Click on the Get Token button in the top right of the Explorer.
Choose the option Get User Access Token.
In the following dialog don't check any boxes, just click the blue Get Access Token button.
You'll see a Facebook Login Dialog, click **OK" here to proceed.

You can use the graph api explorer as curl, but if you want to try it with a real curl the sintaxis is as follows for last api v2.8:

curl -i -H 'Authorization: Bearer YOUR_ACCES_TOKEN' -XGET 'https://graph.facebook.com/v2.8/me'

in my case:

toni@MBP-de-Antonio  ~  curl -i -H 'Authorization: Bearer MY-ACCES_TOKEN' -XGET 'https://graph.facebook.com/v2.8/me'
HTTP/1.1 200 OK
x-app-usage: {"call_count":2,"total_cputime":3,"total_time":3}
Expires: Sat, 01 Jan 2000 00:00:00 GMT
x-fb-trace-id: BnLv25AHTjq
facebook-api-version: v2.8
Content-Type: application/json; charset=UTF-8
x-fb-rev: 2929740
Cache-Control: private, no-cache, no-store, must-revalidate
Pragma: no-cache
ETag: "39875e94193dcd62dcbbf583fc0008c110820a6c"
Access-Control-Allow-Origin: *
X-FB-Debug: fvO9W8Bfl+BihEy/3aZyzOiMrXOkrbK8q1I3Xk2wYnI7sSujZNC6vQzR4RoTWK7K3Hx6EdzoE2kZ/aWhsXe4OA==
Date: Sat, 01 Apr 2017 06:55:52 GMT
Connection: keep-alive
Content-Length: 61

{"name":"Antonio Juan Querol Giner","id":"10204458008519686"}%

Upvotes: 5

Tommy Crush
Tommy Crush

Reputation: 2800

Have you tried using the debugger? Debug your access token here, it'll tell you abou that access token, and if its tied to a user: https://developers.facebook.com/tools/debug

Also, why are you using POST to get /me/friends?

Upvotes: 0

antman
antman

Reputation: 227

I think your issue may be the "/me" identifier you're using when you try to access your own data. (Depending on what your client ID is set as you may be referring to the application instead of yourself, try it with your profiles ID instead of "/me").

Also check this out https://stackoverflow.com/a/6701982/1546542

Upvotes: 0

Related Questions