Facebook PHP Graph API未返回完整数据 [英] Facebook PHP Graph API not returning complete data
问题描述
我在使用Facebook的PHP SDK版本4.0时遇到问题.
I'm having an issue with Facebook's PHP SDK version 4.0.
我只是想通过Graph API检索insights/page_fans_city
指标:
I'm simply trying to retrieve the insights/page_fans_city
metric via the Graph API:
$request = new FacebookRequest($session, 'GET',
'/{my object}/insights/page_fans_city',
array('period' => 'lifetime'));
$response = $request->execute();
$client_graph_object = $response->getGraphObject();
print_r($client_graph_object);
但是,不会返回任何数据:
However, no data is returned:
Facebook\GraphObject Object
(
[backingData:protected] => Array
(
[data] => Array
(
)
[paging] => stdClass Object
(
[previous] => https://graph.facebook.com/v2.0/...
[next] => https://graph.facebook.com/v2.0/...
)
)
)
我知道我拥有要查询的数据.我可以通过Graph Explorer发出完全相同的请求:
I know that I have the Insights data that I'm requesting. I can make the exact same request via the Graph Explorer:
→/v.2.0/{我的对象}/insights/page_fans_city?period = lifetime
{
"data": [
{
"id": "{my object}/insights/page_fans_city/lifetime",
"name": "page_fans_city",
"period": "lifetime",
"values": [
{
"value": {
...
},
"end_time": "2014-08-01T07:00:00+0000"
},
{
"value": {
...
},
"end_time": "2014-08-02T07:00:00+0000"
}
],
"title": "Lifetime Likes by City",
"description": "Lifetime: Aggregated Facebook location data, sorted by city, about the people who like your Page. (Unique Users)"
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.0/...,
"next": "https://graph.facebook.com/v2.0/...
}
}
我应该注意,如果我省略了page_fans_city
段,我将 am 接收数据.省略时-我只能查看page_fans_country
的数据.因此
I should note that I am receiving data if I omit the page_fans_city
segment. When it's omitted- I can view data for page_fans_country
only. Therefore
$request = new FacebookRequest($session, 'GET',
'/{myobject}/insights/page_fans_country',
array('period' => 'lifetime'));
和
$request = new FacebookRequest($session, 'GET',
'/{myobject}/insights',
array('period' => 'lifetime'));
将为我工作...
我怀疑这是我的Access令牌-但我不确定为什么会是这种情况.我创建的应用仅需要read_insights
权限.
I suspect it's my Access token- but I'm not sure why that would be the case. The app that I created only requires the read_insights
permission.
有什么想法或建议吗?
预先感谢,
迈克
Thanks in advance,
Mike
推荐答案
这是一个权限问题. 如果您看到过:
It was a permissions issue. If you ever see:
{
"data": [
],
...
}
您的访问令牌可能没有足够的特权来访问您所请求的数据(即根本没有数据).
It's likely your access token does not have sufficient privileges to access the data you're requesting (that or there's simply no data).
我的问题是,即使我是应用程序的开发者 ,并且它已被Facebook批准(具有manage_pages
和read_insights
权限)-我无法使用应用访问令牌以获取见解数据.
My problem was that even though I was the Developer of the app and it was approved by Facebook (with the manage_pages
and read_insights
permissions)- I could not use an app access token to retrieve the insights data.
我需要一个用户访问令牌!
我通过按 stackoverflow线程也很有用.
I easily generated the user access token by manually creating a login flow per Facebook's documentation. This stackoverflow thread was useful, too.
有关Facebook令牌的更多信息,此处.
More info on Facebook tokens here.
希望这对遇到这个问题的人有所帮助!
Hope this helps anyone who stumbles across this thread!
-迈克
这篇关于Facebook PHP Graph API未返回完整数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!