[英]Facebook API “Unsupported get request.” on facebook page when using App token
[英]Facebook API - Unsupported get request for page/post insights
我知道关于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,尝试了许多组合,但似乎无法获得任何回报。 我甚至尝试使用正确的权限生成新令牌无济于事。 我试过的一些组合:
(#12) singular statuses API is deprecated for versions v2.4 and higher
<POST_ID>/insights
- (#12) singular statuses API is deprecated for versions v2.4 and higher
<PAGE_ID>/insights
- 显示页面的所有见解,不显示每个特定帖子 有谁知道我哪里出错了?
干杯
除了在每个请求中始终具有正确的访问令牌之外,还有文档
包含一个提示:
/ {post-id} / insight(仅限页面帖子)* *注意:Graph API对象{post-id}需要以API调用返回的相同格式指定,以获取页面帖子列表 - 不要尝试拆分或组合其他ID以形成帖子ID
基线:尽量使用
$request = $postId . '/' . FB_REQUEST;
代替
$request = FB_ACCOUNT_ID . '_' . $postId . '/' . FB_REQUEST;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.