Carlos
Carlos

Reputation: 1822

Facebook API fails and Graph works. Why?

I have a Facebook app that works fine when I call $facebook->api('/me'), it returns all the user information, but it fails when I call $facebook->api('/100006737731259'). The error I get is:

array("error" => array("message" => "Unsupported get request.", "type" => "GraphMethodException", "code" => 100))

And the strange thing is that if I open my browser and go to http://graph.facebook.com/100006737731259 it returns all the information with no problem (it is one test user for my app).

Have you ever had a problem like it? I do not know what can I be doing wrong.

Thank you very much

Upvotes: 0

Views: 137

Answers (2)

林果皞
林果皞

Reputation: 7793

When call this API for test user, you can put empty access token OR just don't put access_token parameter at all, then you can solve it.

If you really want to put the access_token, there's the rule you have to follow:

Prohibited access_token:

  1. Normal user's access token

  2. Other app's test user access token

  3. Other app access token

Allowed access_token:

  1. Test user's access token(Either the test user is current app's other test user or this test user 100006737731259, both is allowed!) retrieved from https://graph.facebook.com/APP_ID/accounts/test-users?installed=true&name=TEST_USER_NAME&locale=en_US&permissions=read_stream&method=post&access_token=APP_ACCESS_TOKEN (Replace the relevant APP_ID, TEST_USER_NAME, and APP_ACCESS_TOKEN)

  2. Current App Access token

    *APP_ACCESS_TOKEN can be retrieved from https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=APP_SECRET&grant_type=client_credentials (Replace the relevant APP_SECRET)

    **App Secret can be get from https://developers.facebook.com/x/apps/APP_ID/settings/ (Replace relevant APP_ID)

The proof is, if you request with other user access token, https://graph.facebook.com/100006737731259?access_token=PROHIBITED_ACCESS_TOKEN at web browser, you would get error eventually.

But if you do https://graph.facebook.com/100006737731259?access_token=Allowed_ACCESS_TOKEN OR https://graph.facebook.com/100006737731259?access_token= (left the access_token value empty) with your web browser, then you can get the data.

Upvotes: 1

Bruno Barreto
Bruno Barreto

Reputation: 69

This is a problem that only occurs with test users. I don't know why, but it is. If you use a real user, this will not happen.

Upvotes: 0

Related Questions