I am doing some integration with Facebook Open Graph using their oAuth flow and having issues with parsing query string parameters they return.
On my callback URL, they pass back an “access_token” parameter with a hash (#). so the callback would be:
http://mydomain.com/callback.php#access_token=foobar123
where foobar123 is my access token I’m trying to parse out.
However, no matter what I do, my PHP code cannot see if and I’ve done every debug trick I know (even using phpinfo() to go through everything). The URL is stated only as http://mydomain.com/callback.php. It’s as if the rest of the URL isn’t really there!
This code returns nothing:
$token = $_REQUEST['access_token'];
Any help would be greatly appreciated… I’m obviously missing something simple.
The url fragment (the part after #) is never passed to the server and so the PHP script would never see it.
The way you can handle it is using javascript on callback page which would take the url’s hash part and post it to another page as query string parameter.
callback1.php
callback2.php
Although I’d suggest you have a look at Facebook Javascript and PHP SDK for what you’re trying to do. All the basic oAuth functionality is already built in there.