Facebook Graph API(#190)必须使用页面访问令牌调用此方法

Val*_*eri 3 facebook facebook-graph-api facebook-insights

我从Facebook Graph API获得的数据来自Facebook Graph API超过一年.而最近开始了我的所有请求(像{id}/insights)带一个错误返回:(#190) This method must be called with a Page Access Token.但Access令牌包含范围manage_pages,read_insights.有任何想法吗?

Ach*_*dja 11

manage_pages,read_insights

这将为用户提供access_token可用于管理页面和检查见解的用户,

但是/insights自2018年5月5日以来,任何端点都需要页面令牌

使用您的manage_pages范围并user_token获取页面访问令牌

向此端点发送get请求

GET /{page-id}?fields=access_token 
Run Code Online (Sandbox Code Playgroud)

产量

{
  "access_token": "{your-page-access-token}",
  "id": "{page-id}"
}
Run Code Online (Sandbox Code Playgroud)

您现在可以使用返回的访问令牌来调用/insights端点.

  • 这对我不起作用。当我使用`GET / {page-id}?fields = user_access_token`时,只有在节点类型(Page)上尝试访问不存在的字段(user_access_token)。 (2认同)

Jac*_*łan 6

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.
Run Code Online (Sandbox Code Playgroud)

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.