简体   繁体   English

Facebook PHP Graph API未返回完整数据

[英]Facebook PHP Graph API not returning complete data

I'm having an issue with Facebook's PHP SDK version 4.0. 我在使用Facebook的PHP SDK版本4.0时遇到问题。

I'm simply trying to retrieve the insights/page_fans_city metric via the Graph API: 我只是想通过Graph API检索insights/page_fans_city指标:

$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/...
            )

    )

)


I know that I have the Insights data that I'm requesting. 我知道我拥有要查询的数据。 I can make the exact same request via the Graph Explorer: 我可以通过Graph Explorer发出完全相同的请求:

→ /v.2.0/{my object}/insights/page_fans_city?period=lifetime →/v.2.0/ {我的对象} / insights / page_fans_city?period =生存时间

{
  "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/...
  }
}


I should note that I am receiving data if I omit the page_fans_city segment. 我要指出, 收到的数据,如果我省略page_fans_city段。 When it's omitted- I can view data for page_fans_country only. 省略时-我只能查看page_fans_country数据。 Therefore 因此

$request = new FacebookRequest($session, 'GET', 
    '/{myobject}/insights/page_fans_country', 
    array('period' => 'lifetime'));

and

$request = new FacebookRequest($session, 'GET', 
    '/{myobject}/insights', 
    array('period' => 'lifetime'));

will work for me ... 为我工作...

I suspect it's my Access token- but I'm not sure why that would be the case. 我怀疑这是我的Access令牌-但我不确定为什么会是这种情况。 The app that I created only requires the read_insights permission. 我创建的应用程序仅需要read_insights权限。

Any thoughts or suggestions? 有什么想法或建议吗?


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). 您的访问令牌很可能没有足够的特权来访问您所请求的数据(或根本没有数据)。

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. 我的问题是,即使我是该应用程序的开发人员, 并且得到了Facebook的批准(具有manage_pagesread_insights权限)-我无法使用应用程序访问令牌来检索见解数据。

I needed a user access token! 我需要一个用户访问令牌!

I easily generated the user access token by manually creating a login flow per Facebook's documentation . 通过按照Facebook的文档手动创建登录流程,我可以轻松生成用户访问令牌。 This stackoverflow thread was useful, too. 这个stackoverflow线程也很有用。

More info on Facebook tokens here . 有关Facebook令牌的更多信息,请点击此处

Hope this helps anyone who stumbles across this thread! 希望这对遇到这个问题的人有所帮助!

-Mike -麦克风

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM