Reputation: 16283
I know there's a multitude of questions regarding Facebook's SDK and API and this specific error response, however none of them seem to answer my question.
I run a Facebook page and until a couple of days ago I had some code running that would collect the insights
data for each post on my Facebook page.
This is what I was doing:
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()}");
}
}
The above code was working great until a couple of days ago when I noticed my stats weren't pulling in. After some investigation and playing around using the Graph API Explorer I have found that I get the following output:
EXCEPTION: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
And using the 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"
}
}
No matter what I have tried I don't seem to be able to get the insights for a single post on a page again. I've tried playing with the Graph API Explorer, trying a number of combinations but don't seem to be able to get anything back. I've even tried generating new tokens with the correct permissions to no avail. Some of the combinations I've tried:
<POST_ID>/insights
- (#12) singular statuses API is deprecated for versions v2.4 and higher
<PAGE_ID>/insights
- Shows all insights for page, nothing about each specific postDoes anyone know where I'm going wrong?
Cheers
Upvotes: 3
Views: 3041
Reputation: 31479
Other than always having a correct access token in every request, the docs at
contain a hint:
/{post-id}/insights (Page posts only)* *Note: The Graph API object {post-id} needs to be specified in the same format returned by the API call to fetch a list of page posts - do not attempt to split or combine other IDs to form a post ID
Baseline: Try to just use
$request = $postId . '/' . FB_REQUEST;
instead of
$request = FB_ACCOUNT_ID . '_' . $postId . '/' . FB_REQUEST;
Upvotes: 2