Facebook Graph API (#190) This method must be call

2019-02-16 02:09发布

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?

2条回答
欢心
2楼-- · 2019-02-16 02:27

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.

查看更多
手持菜刀,她持情操
3楼-- · 2019-02-16 02:41

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

For PHP

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.

查看更多
登录 后发表回答