Happyr / LinkedIn-API-client

A library to connect with LinkedIn API. Perfect if you are looking for an API client or SDK for LinkedIn
MIT License
198 stars 97 forks source link

How can I inject oauth2_access_token? #10

Closed rajeshmeniya closed 10 years ago

rajeshmeniya commented 10 years ago

I have oauth2 access token and want to use to share on linkedin, can you please tell me how to do this?

I have both OAuth User Token: "randomUserTokenGeneratedAtLinkedin" OAuth User Secret: "randomUserSecretGeneratedAtLinkedin"

which and how to use it??

rajeshmeniya commented 10 years ago

tried following

$x = $linkedIn->api('v1/people/~/shares', array('format'=>'xml', 'oauth2_access_token'=>'randomUserTokenGeneratedAtLinkedin'), 'POST', $xml);

print_r($x);

But, it returns below error " 401 1404824467258 PLA5D8UVDG 0 Invalid access token. "

Nyholm commented 10 years ago

The user access token is not the same as the OAuth tokens. The OAuth is to authenticate you application. The user access token is to authenticate your application with a user...

Look at the example in the Readme. It tells you how to authenticate a user. When a user is authenticate you may run $linkedIn->getAccessToken() to get a user access token. You may save that token in your application. At some later point you fetch that token from your storage and...

$token= //from database
$linkedIn->setAccessToken($token);
$linkedIn->api('v1/people/~/shares', array('format'=>'xml'), 'POST', $xml);
rajeshmeniya commented 10 years ago

Ok, but how can I share from backend script (cron).

rajeshmeniya commented 10 years ago

Is it possible using OAuthTokens generated at linkedin application setting.

Nyholm commented 10 years ago

You do exactly the same if you want to authenticate from a backend script. Just authenticate yourself and save your access token. Then run the code I provided you..

You may not use the OAuthTokens as access tokens. That is how the LinkedIn API is designed.