I get data from the Facebook insights via Facebook Graph API more than year. And recently started all my requests (like {id}/insights
) to return with an error: (#190) This method must be called with a Page Access Token
.
But the Access token contains scopes manage_pages,read_insights
.
Any ideas?
A Facebook Graph API is a programming tool designed to support more access to conventions on the Facebook social media platform. The core of Facebook's platform is something called the "social graph," which is the element responsible for facilitating all of the online relationships between people, places, things, etc.
The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.
API Version Deprecations: As part of Facebook's Graph API and Marketing API, please note the upcoming deprecations: August 3, 2021: Graph API v3. 3 will be deprecated and removed from the platform. August 25, 2021 Marketing API v9.
manage_pages,read_insights
This will give a user access_token
, that u can use to manage pages & check insights,
But a page token became required for any /insights
endpoint since 5th feb 2018
Use your manage_pages
scope & user_token
to get a Page access token
Send a get request to this endpoint
GET /{page-id}?fields=access_token
Output
{
"access_token": "{your-page-access-token}",
"id": "{page-id}"
}
You can use the returned access token to call /insights
endpoint now.
As I cant add comment I'll write it here.
Field name is access_token
which you can check here with your page id.
https://developers.facebook.com/tools/explorer/?method=GET&path=page-id%3Ffields%3Daccess_token&version=v2.12
If you had your script in PHP, using Facebook SDK for PHP and now it brokes, you just need to retrieve token and pass it instead of access/refresh token you were using.
//Retrieve new 'page access token'.
$token = $fbApiClient -> get( "/{$pageId}?fields=access_token") -> getGraphNode()-> asArray();
//$q is your insights query which was working until now :(
//But with page acces token it will work again.
$response = $fbApiClient -> get( $q, $token['access_token']) -> getGraphEdge();
//(...) rest of script.
I think its easily adaptable to other languages too. Also you can (and propably should) store page access token and use it wherever you need, instead of retrieving it each time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With