11

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?

Valeri
  • 327
  • 1
  • 5
  • 15

3 Answers3

16

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.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
Achraf Khouadja
  • 6,119
  • 4
  • 27
  • 39
  • Can you link to where Facebook mentions this change is effective since Feb 5th 2018? I couldn't find it.. – Noam Feb 22 '18 at 07:45
  • I do see this in v2.11 changelog "/page/insights — This edge will require a Page access token of the page in question for all metrics." - but this is also affecting calls for older versions of the API. How can that be? Is this documented anywhere? – Noam Feb 22 '18 at 08:05
  • 1
    yes, they had a notice, a 90 day breaking changes or something, also when u check docs for older versions at the top it will mention that all versions are affected by this change. – Achraf Khouadja Feb 22 '18 at 08:43
  • 2
    This doesn't work for me. I only get `Tried accessing nonexisting field (user_access_token) on node type (Page)` when I use `GET /{page-id}?fields=user_access_token` – Jesse Novotny Aug 20 '18 at 17:14
  • 1
    @JesseNovotny I'm having the exact same issue, did you find an answer? – twigg Sep 04 '18 at 12:49
  • i fixed the answer, it is access_token, not user_access_token – andyrandy Sep 04 '18 at 13:13
  • @twigg sadly no. Worse yet, FB has implemented an app review process which blocks endpoints until they are approved. The problem is that this review process requires that I demonstrate how we use each specific endpoint which is impossible since the endpoint is not yet approved. Every request returns "Application does not have permission". It's a royal catch 22 and contacting their support team has proven fruitless. – Jesse Novotny Sep 05 '18 at 15:11
  • Downvote. This doesn't work. I request WITH the same token as I receive for `fields=access_token`. Wrong answer – Green May 30 '19 at 15:16
  • 1
    @Green you must misunderstand the answer, it works! I can help you if you need further help – Achraf Khouadja May 30 '19 at 22:37
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.

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.

Community
  • 1
  • 1
Jacek Rosłan
  • 333
  • 4
  • 10
0

You can get the Page Access Token easily.

After collecting the access_token from the OAuth session, make a call to the /me/accounts endpoint with the fields=access_token,name,id parameter.

In the response body, you will find the Page Access Token. Save this token and use it when making your insights query or any other API request related to the page.

desertnaut
  • 57,590
  • 26
  • 140
  • 166