I am working on the PHP application, that captures "Access Token", when user click on register with Linkedin, I use that access token to get all the related information from the user's Linkedin profile.
I now want to include LinkedIn Send a message feature http://developer.linkedin.com/documents/sample-code-sending-message.
Is there any way I can use the Send a message feature with authentication process using user's access token without showing user to login with linkedIn again to send a message?
Yes there is, just store the token in a database (it should be good for 60days) and reuse it in your requests. If the token expires you will have to reauthorize a new one.
Example with my linkedin class from: https://github.com/EJTH/SLinkedIn
But it should be pretty similar with other classes or extensions.
$ln = new SimpleLinkedIn('APIKEY','APISECRET'); $ln->addScope('rw_nus'); $ln->setTokenData($myUserObj->getLinkedinToken() /* Get token from db */); if($ln->authorize()){ /* Do OAuth stuff */ $user = $ln->fetch('GET', '/v1/people/~:(firstName,lastName)'); $tokenData = $ln->getTokenData(); /* Save the new token, if it was changed */ $myUserObj->setLinkedinToken($tokenData['access_token']); } else { /* User declined authorization */ }
Just remember that your token must have the scope for the action you want to perform.