开发者

Facebook Insights for Page via the API

开发者 https://www.devze.com 2022-12-29 19:54 出处:网络
Using the new API, is it possible to get the insights (analytics) data from a page that you are an admin of?

Using the new API, is it possible to get the insights (analytics) data from a page that you are an admin of?

I can successfully get the data from an app I own, but its not clear how to do this for a page.

If not, is it p开发者_Python百科ossible to download the CSV of data from the API?


I've got the answer:

First you must create an app, and request permission for that 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 the user authorizes, facebook will issue a new token.

that token must be passed to the graph accounts api

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]; 


  ?>

with that token you must now access the graph api to get tokens for the pages the user owns:

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

you will get an array with the pages and they're respective tokens.

now you must access the graph insights endpoint:

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

you can use until:yyyy-mm-dd or since to limit results, it even gets you a paging link.

0

精彩评论

暂无评论...
验证码 换一张
取 消