1

I'm having an issue with Facebook's PHP SDK version 4.0.

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

    )

)


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


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'));

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. The app that I created only requires the read_insights permission.

Any thoughts or suggestions?


Thanks in advance,
Mike

1
  • It's definately a token issue. In the Graph API Explorer- my App Token (for my blurred-out application name) does not return any results (screenshot here). If I use the drop down menu and change the application to the Graph API Explorer and generate an Access Token- I can see all the data I need (screenshot here). I think the better question is- what do I need to do to my App Token to generate these results? Commented Aug 8, 2014 at 15:37

1 Answer 1

2

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.

I needed a user access token!

I easily generated the user access token by manually creating a login flow per Facebook's documentation. This stackoverflow thread was useful, too.

More info on Facebook tokens here.

Hope this helps anyone who stumbles across this thread!

-Mike

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.