Why would the same FB insights query work in a browser and Graph API Explorer, but return null with PHP SDK?

StackOverflow https://stackoverflow.com/questions/19965539

Question

As you can see in this picture

enter image description here

  • I have a valid long-life Access Token for my app (390068587730802) with the following permissions: ads_management, manage_pages, read_insights, user_friends
  • I can use it to get data on another accessible app (50813163906) using the Graph API Explorer,
  • $facebook->getUser(); does return my user id
  • HOWEVER, I get NULL from the same request via the PHP SDK.

I have tested locally on xampp and on an apache server. I have updated the PHP SDK today to include the latest changes surrounding offline_access and long life tokens. I have read dozens of posts and FB documentation. I´m glad to read more you think will help, but please note that my token is valid, long lived, and I am successfully getting "/me" from the graph API. All of this happens under http or https.

UPDATE "Facebook: Sorry, something went wrong. We're working on getting this fixed as soon as we can."

As seen in this next picture below, I´ve var_dump´d the CURL options to verify the correct access_token and URL is actually being called. Furthermore, I can copy these urls directly into the browser and get complete data return!!

enter image description here

If during my testing I have created "two active sessions" - as some docs warn - how can you test for that? Most importantly, why would the same FB insights query work in the Graph API Explorer, but return null with PHP SDK?

Était-ce utile?

La solution

It turns out that "since=30 days ago" was giving a 400 (bad request) response. This error was not showing up in the CURL errors. Only via

curl_getinfo($this -> ch,CURLINFO_HTTP_CODE);

When i changed

$period = "{$period} days ago";

to

$period = urlencode("{$period} days ago");
//or 
$period = strtotime("- {$period} days");

everything worked via CURL.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top