首页 文章

Facebook API - 不支持获取页面/帖子洞察的请求

提问于
浏览
3

我知道关于Facebook的SDK和API以及这个特定的错误响应有很多问题,但是它们似乎都没有回答我的问题 .

我运行一个Facebook页面,直到几天前我运行了一些代码才能收集我的Facebook页面上每个帖子的 insights 数据 .

这就是我在做的事情:

define('FB_APP_ACCESS_TOKEN', 'omitted'); // Never expires, has permission to read insight data (and more)
define('FB_APP_ID', 'omitted'); // ID of my Facebook App
define('FB_APP_SECRET', 'omitted'); // Secret for App
define('FB_ACCOUNT_ID', 'omitted'); // Facebook ID of my page
define('FB_REQUEST', 'insights/post_impressions_unique,post_consumptions_by_type,post_negative_feedback_by_type,post_consumptions,post_story_adds_by_action_type');

// .. Require Facebook SDK (Using composer)
// .. Other processing


// Initialise the Facebook SDK with our credentials and permanent access token.
$fb = new Facebook\Facebook([
    'app_id' => FB_APP_ID,
    'app_secret' => FB_APP_SECRET,
    'default_graph_version' => 'v2.2'
]);
$fb->setDefaultAccessToken(FB_APP_ACCESS_TOKEN);


// .. Grab some posts from my database
foreach ($posts as $post) {
    $postId = $post['id'];
    $request = FB_ACCOUNT_ID . '_' . $postId . '/' . FB_REQUEST;
    // Request will now contain something like...
    // <PAGE_ID>_<POST_ID>/insights/post_impressions_unique,post_consumptions_by_type,post_negative_feedback_by_type,post_consumptions,post_story_adds_by_action_type

    try {
        $fb->get($response); // This line fails and throw exception

        // .. Rest of my processing
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        die("\nEXCEPTION: {$e->getMessage()}\n{$e->getTraceAsString()}");
    }
}

上面的代码工作得很好,直到几天前我注意到我的统计数据没有进入 . 经过一些调查并使用Graph API Explorer我发现我得到以下输出:

EXCEPTION:不支持的获取请求 . 请阅读https://developers.facebook.com/docs/graph-api上的Graph API文档

并使用Graph API Explorer:

{
  "error": {
    "message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
    "type": "GraphMethodException",
    "code": 100,
    "fbtrace_id": "XXXXXXX"
  }
}

无论我尝试过什么,我似乎无法再次获得页面上单个帖子的见解 . 我尝试使用Graph API Explorer,尝试了许多组合,但似乎无法获得任何回报 . 我甚至尝试使用正确的权限生成新令牌无济于事 . 我试过的一些组合:

  • <POST_ID>/insights - (#12) singular statuses API is deprecated for versions v2.4 and higher

  • <PAGE_ID>/insights - 显示页面的所有见解,不显示每个特定帖子

有谁知道我哪里出错了?

干杯

1 回答

  • 2

    除了在每个请求中始终具有正确的访问令牌之外,还有文档

    包含一个提示:

    / / insights(仅限页面帖子)* *注意:Graph API对象需要以API调用返回的相同格式指定,以获取页面帖子列表 - 不要尝试拆分或组合其他ID以形成帖子ID

    基线:尽量使用

    $request = $postId . '/' . FB_REQUEST;
    

    代替

    $request = FB_ACCOUNT_ID . '_' . $postId . '/' . FB_REQUEST;
    

相关问题