通过API对Facebook进行分析 [英] Facebook Insights for Page via the API

查看:135
本文介绍了通过API对Facebook进行分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用新的API,是否可以从您作为管理员的页面获取洞察(分析)数据?



我可以成功获取数据从我自己的应用程序,但它不清楚如何做一个页面。



如果没有,是否可以从API下载数据CSV? / p>

解决方案

我有答案:



首先你必须创建一个应用程序,并请求该用户的许可:

  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 

用户授权后,将发出一个新的令牌。



该令牌必须传递给图表帐户api



在php: / p>

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以获取用户拥有的页面的标记: / p>

  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或自从限制结果,甚至可以让你分页链接。


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 possible 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.

这篇关于通过API对Facebook进行分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆