0

I'm authenticating a user using the Linkedin API and everything is fine up until I make the call to get the access token. E.g:

https://www.linkedin.com/uas/oauth2/accessToken?
grant_type=authorization_code&code=12345
&redirect_uri=https://myredirect.com/callback.php&client_id=123456789
&client_secret=12345

Usually these types of calls return the access_token in the URL so I can either use $_GET or $_POST, but this returns a basic page with the JSON response:

{"access_token":"ABCDEFG","expires_in":5183078}

How can I take that access_token and put it into a $_SESSION variable? Can I split the response and then use AJAX somehow?

Hook
  • 305
  • 3
  • 12
  • php code will be required for better help ? – Jigar Oct 18 '15 at 05:27
  • 1
    btw, use curl or file_get_contents to get the JSON response in string then use `json_decode`. something like this: http://stackoverflow.com/questions/17016506/how-to-parse-json-response-from-curl – Jigar Oct 18 '15 at 05:28
  • Thanks Jigar! Exactly what I used to solve it – Hook Oct 18 '15 at 17:44

2 Answers2

0

Take the $json_var and use json_decode($json_var, true); That will turn the $json_var into an associative array

Baine Sumpin
  • 142
  • 5
  • Problem is I don't know how to even get it into a variable, it's displayed automatically after using the URL – Hook Oct 18 '15 at 04:46
0

Try this

session_start();
$_SESSION['f1']="Hai this is test";//This seesion will be lost
$json='{"access_token":"ABCDEFG","expires_in":5183078}';
$_SESSION=json_decode($json,true);
print_r($_SESSION);

When we use $_SESSION as left side variable all the keys which are previously stored values are ignored.So be careful with that.

ManiMuthuPandi
  • 1,594
  • 2
  • 26
  • 46
  • `$_SESSION=json_decode($json,true);` is a VERY BAD IDEA ! you are overwriting the whole global session variable. – Jigar Oct 18 '15 at 05:23