0

I have to get value of access_token from a URL, like:

localhost/facebook/#access_token=xyz

$_GET['access_token'] doesn't work. How can I get the value of access_token?

Charlie
  • 11,380
  • 19
  • 83
  • 138
Meow
  • 105
  • 1
  • 12

2 Answers2

1

Use getAccessToken

$facebook->getAccessToken();

https://developers.facebook.com/docs/reference/php/facebook-getAccessToken/

$user = $facebook->getUser();
echo $facebook->getAccessToken();
if(!$user){
    $loginUrl = $facebook->getLoginUrl();
    echo '<a href="$loginUrl">Login with Facebook</a>';
}

Clicking login with take you to fb, you login/accept whatever, then it redirects you back to your page and you get your access token.

ElefantPhace
  • 3,806
  • 3
  • 20
  • 36
0

I believe the hash part of the URL isn't sent to PHP, so can't be accessed via PHP. Javascript can access it, and can then pass it onto PHP.

There is a guide here showing how.

flauntster
  • 2,008
  • 13
  • 20