Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Send message

how do i send a message/notification with the linkedin api?

You use LinkedIn Access Token and send by function message.

<?php
// base or site url is the site where code linked in button is kept for signup
$baseURL = 'http://localhost/linkedin/';

/* callback or redirect url is the page you want to open 
 * after successful getting of data i.e. index.php page 
 * (must be same in linkedin dashboard) */
$callbackURL = 'http://localhost/linkedin/process.php'; 

// APP ID (will receive from linkedin dashboard)
$linkedinApiKey = 'your api key';

// APP Client
$linkedinApiSecret = 'your api secret';

// This is fixed no need to change
$linkedinScope = 'r_basicprofile r_emailaddress';
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top