ashwinks / PHP-LinkedIn-SDK

A PHP wrapper for the LinkedIn API
94 stars 74 forks source link

Invalid access token #18

Closed lifeboatpres closed 9 years ago

lifeboatpres commented 9 years ago

I'm getting the error invalid access token.

Here's more info: In response to the authorization I am told https://lifeboat.com/linkedin.post/?code=AQRS2NUSZAXDOX6pAaX5NAGxzm4rBqIpL95G-c31XRq9YULeeZ55TxTzb5IsBGj3Jt7SJNG2bIZj7x8zQdyRVxWMbhMPJBjflhWXM3OGQWNAVG28-rA&state=552e31c1156d94.09928605

So I set my authorization code to AQRS2NUSZAXDOX6pAaX5NAGxzm4rBqIpL95G-c31XRq9YULeeZ55TxTzb5IsBGj3Jt7SJNG2bIZj7x8zQdyRVxWMbhMPJBjflhWXM3OGQWNAVG28-rA and try

$token = $li->getAccessToken(); print "Token is $token\n";

$info = $li->get('/people/~:(first-name,last-name,positions)');

And get:

Token is AQRS2NUSZAXDOX6pAaX5NAGxzm4rBqIpL95G-c31XRq9YULeeZ55TxTzb5IsBGj3Jt7SJNG2bIZj7x8zQdyRVxWMbhMPJBjflhWXM3OGQWNAVG28-rA

PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Request Error: Invalid access token.. Raw Response: Array ( [errorCode] => 0 [message] => Invalid access token. [requestId] => B7DCHS9W2U [status] => 401 [timestamp] => 1429091044022 ) ' in /u/home/lifeboat/linkedin.post.php:364

lifeboatpres commented 9 years ago

I found the answer. The token is not AQRS2NUSZAXDOX6pAaX5NAGxzm4rBqIpL95G-c31XRq9YULeeZ55TxTzb5IsBGj3Jt7SJNG2bIZj7x8zQdyRVxWMbhMPJBjflhWXM3OGQWNAVG28-rA

Instead it is the result of $token = $li->getAccessToken($_REQUEST['code']); due to step 3 documented at https://developer.linkedin.com/docs/oauth2.