简体   繁体   中英

Facebook error 2500 with valid access token

Previously I have been able to access the Facebook OAuth services through cURL in PHP. However, I am now getting a 2500 error (In this case An active access token must be used to query information about the current user. ). I can access the information by using the URL straight through my web browser, however when I try to access it with cURL in PHP it doesnt work. I am using Facebook API v1.0, and the token is being generated with the Graph API Explorer.

What I have tried

I have tried creating a new access token, as well as tried using Facebook API v2.0 and the unversioned API. As I said above, I have tried using the exact same URLs in my browser, which works. I have also tried clearing cookies and trying again, as well as trying a whole different browser.

I have seen some of the other questions on SO which relate to this question but none of the answers work for me.

The code

The URL I am using is simply a call to the /me/home edge.

https://graph.facebook.com/v1.0/me/home/?since=1402913078&until=1402913213&access_token=<access token here>

Where <access token here> is the access token

The PHP cURL code looks like the following:

$url = "<the url here>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($ch);
// get the response here...

It turns out that the actual URL being requested by cURL was different to the one that should have been being requested (the GET parameters were missing). This was caused by another location in the code.

To verify that the URL that is being requested is the same as the one passed to cURL, use the following code:

$requested_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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