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?

8
  • 2
    You get it with JavaScript, not PHP. Commented Feb 19, 2014 at 4:04
  • because you have /# in the url and rest url it not getting with $_GET[] Commented Feb 19, 2014 at 4:05
  • How to get the value from javascript ? Please some hints. Commented Feb 19, 2014 at 4:06
  • is your response_type set to token? if so try code instead Commented Feb 19, 2014 at 4:06
  • 1
    @NAB: a first hint: try google first Commented Feb 19, 2014 at 4:06

2 Answers 2

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.

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

5 Comments

Actually I need token.When I add token its return # .But response type is only code it works.
You can still get the token from using code. It just passes it through and you use $_GET['code']
I didn't find any method to get access token form code. Please any suggestion?
$facebook->getAccessToken(); get only an active access token. but i need accessToken from code. In my case redirect url in different . so no any cookies is there
I'm assuming you're using the login url?
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.

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.