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

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

我一直在尝试使用 cURL 访问有关我的 Facebook PAGE 的信息。我在 Graph Explorer 中传递了 url me/accounts,其中显示了一些数据,如下所示:

{
  "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=="
    }
  }
}

但是当我试图通过终端在 cURL 和 运行 中获取同样的东西时,它给我一个错误“不支持的 GET 请求

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)
  }
}

页面权限:manage_pages,publish_pages

我检查了年龄限制:它对所有人开放。

那我哪里错了?感谢您的帮助

使用 Graph Explorer 时,每个请求都会自动添加一个访问令牌。如果您通过 cUrl 执行相同的请求而没有明确添加访问令牌作为 URL 参数,那么它将失败。

您需要在调用中添加 access_token 参数,以及具有 manage_pages 权限的访问令牌(替换 {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);
?>