Facebook Insights for Page via API

Using the new API, is it possible to get data (analytics) on the page that you are an administrator?

I can successfully retrieve data from my own application, but it is unclear how to do this for the page.

If not, is it possible to load CSV data from the API?

+3
source share
2 answers

I have an answer:

First you must create an application and request permission for this user:

https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_REDIRECT_URL&scope=offline_access,manage_pages,read_insights,ads_management

After user authorization, facebook will issue a new token.

this token must be passed to api chart counters

in php:

facebook_example_return.php

<?

    $token = explode('=', file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=http://$_SERVER[SERVER_NAME]$_SERVER[PHP_SELF]&client_secret=YOUR_CLIENT_SECRET&code=" . 
    (get_magic_quotes_gpc() ? stripslashes($_GET['code']) : $_GET['code']))); 


    $secretToken = $token[1]; 


  ?>

api, , :

https://graph.facebook.com/me/accounts?access_token=$secretToken

, .

:

https://graph.facebook.com/FB_PAGE_ID/insights?access_token=PAGE_SECRET_TOKEN

: yyyy-mm-dd , .

+5
0

Source: https://habr.com/ru/post/1745047/


All Articles