wes*_*bos 3 facebook facebook-graph-api
使用新API,是否可以从您作为管理员的页面获取洞察(分析)数据?
我可以从我拥有的应用程序中成功获取数据,但不清楚如何为页面执行此操作.
如果没有,是否可以从API下载CSV数据?
我有答案:
首先,您必须创建一个应用程序,并请求该用户的权限:
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
Run Code Online (Sandbox Code Playgroud)
用户授权后,Facebook将发出新令牌.
该令牌必须传递给图表帐户api
在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];
?>
Run Code Online (Sandbox Code Playgroud)
使用该令牌,您现在必须访问图形API以获取用户拥有的页面的令牌:
https://graph.facebook.com/me/accounts?access_token=$secretToken
Run Code Online (Sandbox Code Playgroud)
你将获得一个包含页面的数组,它们是各自的标记.
现在您必须访问图表洞察端点:
https://graph.facebook.com/FB_PAGE_ID/insights?access_token=PAGE_SECRET_TOKEN
Run Code Online (Sandbox Code Playgroud)
您可以使用直到:yyyy-mm-dd或者为了限制结果,它甚至可以为您提供分页链接.
归档时间: |
|
查看次数: |
6220 次 |
最近记录: |