我正在开发PHP应用程序,该应用程序捕获"访问令牌",当用户点击与Linkedin注册时,我使用该访问令牌从用户的Linkedin配置文件中获取所有相关信息。
我现在想包括LinkedIn发送消息功能http://developer.linkedin.com/documents/sample-code-sending-message。
我是否可以使用用户的访问令牌使用带有身份验证过程的发送消息功能,而无需显示用户再次登录linkedIn以发送消息?
是的,只是将令牌存储在数据库中(它应该有效60天)并在您的请求中重用它。如果令牌过期,您必须重新授权一个新的。
例子与我的linkedin类来自:https://github.com/EJTH/SLinkedIn
但它应该与其他类或扩展非常相似。
<>之前$ln = new SimpleLinkedIn('APIKEY','APISECRET');ln -> addScope("rw_nus");$ln->setTokenData($myUserObj->getLinkedinToken()/*从数据库*/获取token);如果(ln ->授权()){/*执行OAuth操作*/$ user = $ ln ->获取(‘得到’,‘/v1/人/~:(firstName、lastName) ');$tokenData = $ln->getTokenData()/*保存新令牌,如果它被更改*/myUserObj -> setLinkedinToken ($ tokenData [' access_token ']);} else {/*用户拒绝授权*/}之前请记住,您的令牌必须具有您想要执行的操作的作用域。
发送消息
如何使用linkedin api发送消息/通知?
您使用LinkedIn Access Token并按功能发送消息
<?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';
?>