Php LinkedIn访问令牌用于验证用户并使用JSAPI发送消息

Php LinkedIn访问令牌用于验证用户并使用JSAPI发送消息,php,javascript,linkedin,linkedin-jsapi,Php,Javascript,Linkedin,Linkedin Jsapi,我正在开发PHP应用程序,它捕获“访问令牌”,当用户单击RegisterwithLinkedIn时,我使用该访问令牌从用户的Linkedin配置文件中获取所有相关信息 我现在想包括LinkedIn发送消息功能 是否有任何方法可以使用“发送消息”功能和使用用户的访问令牌的身份验证过程,而不显示用户再次登录linkedIn以发送消息?是的,只需将令牌存储在数据库中(有效期应为60天)并在您的请求中重复使用即可。如果令牌过期,您必须重新授权一个新的令牌 我的linkedin类示例来自: 但它应该与其

我正在开发PHP应用程序,它捕获“访问令牌”,当用户单击RegisterwithLinkedIn时,我使用该访问令牌从用户的Linkedin配置文件中获取所有相关信息

我现在想包括LinkedIn发送消息功能


是否有任何方法可以使用“发送消息”功能和使用用户的访问令牌的身份验证过程,而不显示用户再次登录linkedIn以发送消息?

是的,只需将令牌存储在数据库中(有效期应为60天)并在您的请求中重复使用即可。如果令牌过期,您必须重新授权一个新的令牌

我的linkedin类示例来自:

但它应该与其他类或扩展非常相似

$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 */ } $ln=new SimpleLinkedIn('APIKEY','APISECRET'); $ln->addScope('rw_nus'); $ln->setTokenData($myUserObj->getLinkedinToken()/*从db获取令牌*/); 如果($ln->authorize()){ /*做OAuth的事情*/ $user=$ln->fetch('GET','/v1/people/~:(firstName,lastName'); $tokenData=$ln->getTokenData(); /*保存新令牌(如果已更改)*/ $myUserObj->setLinkedinToken($tokenData['access_token']); }否则{ /*用户拒绝授权*/ } 请记住,您的令牌必须具有要执行的操作的作用域。

发送消息

您使用LinkedIn访问令牌并通过功能消息发送。


<?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';
?>