Facebook Graph API (#190) This method must be called with a Page Access Token

前端 未结 2 712
慢半拍i
慢半拍i 2020-12-10 18:22

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:

相关标签:
2条回答
  • 2020-12-10 19:01

    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.

    0 讨论(0)
  • 2020-12-10 19:12

    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.

    0 讨论(0)
提交回复
热议问题