Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: Unsupported get request. Please read the Graph API documentation

I have been trying to access the information about my Facebook PAGE using cURL. I passed the url me/accounts in Graph Explorer which shows some data as follows:

{
  "data": [
    {
      "access_token": "tokenString", 
      "category": "Small business", 
      "name": "myPageName", 
      "id": "xxx", 
      "perms": [
        "ADMINISTER", 
        "EDIT_PROFILE", 
        "CREATE_CONTENT", 
        "MODERATE_CONTENT", 
        "CREATE_ADS", 
        "BASIC_ADMIN"
      ]
    }
  ], 
  "paging": {
    "cursors": {
      "before": "MTM4NzYwMjM5NDg5NTUzOQ==", 
      "after": "MTM4NzYwMjM5NDg5NTUzOQ=="
    }
  }
}

But when I tried to get the same thing in cURL and run through terminal it gives me an error "Unsupported GET request"

Code:

<?php
  $url='https://graph.facebook.com/v2.3/me/accounts';
  $ch=curl_init();
  CURL_SETOPT($ch,CURLOPT_URL,$url);
  CURL_SETOPT($ch,CURLOPT_RETURNTRANSFER, 1);
  $json=json_decode(curl_exec($ch));
  var_dump($json);
?>

Error:

object(stdClass)#1 (1) {
  ["error"]=>
  object(stdClass)#2 (3) {
    ["message"]=>
    string(114) "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api"
    ["type"]=>
    string(20) "GraphMethodException"
    ["code"]=>
    int(100)
  }
}

Page permission: manage_pages,publish_pages

I checked for age restrictions: It is open to all.

Then where am I going wrong ? Thanks for any help

like image 623
sunshine Avatar asked Apr 13 '15 07:04

sunshine


1 Answers

When using Graph Explorer, an Access Token is automatically added to each request. If you do the same request via cUrl without explicitly adding an Access Token as URL parameter, then it will fail.

You need to add the access_token parameter to your call, and an Access Token with manage_pages permission (replace {access_token}).

<?php
  $url='https://graph.facebook.com/v2.3/me/accounts?access_token={access_token}';
  $ch=curl_init();
  CURL_SETOPT($ch,CURLOPT_URL,$url);
  CURL_SETOPT($ch,CURLOPT_RETURNTRANSFER, 1);
  $json=json_decode(curl_exec($ch));
  var_dump($json);
?>
like image 51
Tobi Avatar answered Nov 18 '22 11:11

Tobi