对于大多数(如果不是所有)Facebook API调用的对象洞察,我得到一个空数据数组的响应。我在登录时请求以下权限:read_insights,publish_pages,manage_pages。
我要做的一些请求包括:page_views_total,page_impressions,page_fans
FB.api(
"/1493689654199431/insights/page_impressions/lifetime",
function (response) {
if (response && !response.error) {
console.log(response);
}
}
);
回应示例:
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/v2.6/1493689654199431/insights/page_impressions/lifetime?access_token=EAACEdEose0cBAGNO4tT95osm9KIaLlsoxoWPyk7g4J6m3iBwa5ZArxGEZBbeIpILExuTZAC6KFRHfCuccbsOCCQLmRZCItZAAmTs3PXzueCCJ0CVjr6UBB3gZCfClQeeI1PbHZCnJVqZBPHf00Vl6U4Lj6B1FpMhZAqUSdXNvcPDWlAZDZD&debug=all&format=json&method=get&pretty=0&suppress_http_code=1&since=1462194002&until=1462453202",
"next": "https://graph.facebook.com/v2.6/1493689654199431/insights/page_impressions/lifetime?access_token=EAACEdEose0cBAGNO4tT95osm9KIaLlsoxoWPyk7g4J6m3iBwa5ZArxGEZBbeIpILExuTZAC6KFRHfCuccbsOCCQLmRZCItZAAmTs3PXzueCCJ0CVjr6UBB3gZCfClQeeI1PbHZCnJVqZBPHf00Vl6U4Lj6B1FpMhZAqUSdXNvcPDWlAZDZD&debug=all&format=json&method=get&pretty=0&suppress_http_code=1&since=1462712402&until=1462971602"
}
}
答案 0 :(得分:2)
JavaScript SDK默认使用用户令牌,您需要获取并使用Page Insights的Page令牌。你得到一个带有/me/accounts
端点的页面令牌,这就是你如何使用它:
FB.api(
"/1493689654199431/insights/page_impressions/lifetime",
{access_token: pageToken},
function (response) {
if (response && !response.error) {
console.log(response);
}
}
);
您可以在此处调试您的页面令牌:https://developers.facebook.com/tools/debug/accesstoken/
答案 1 :(得分:2)
The reason being, page_impressions takes only three values for period = day, week, days_28.
I tried with
FB.api('/page-id/insights/page_impressions/days_28',{access_token: page-access-token}, function(response){
console.log('page impressions',response);
})
and got data.
Had the same issue of empty data, it got resolved