我正在开发允许用户连接到 linkedin(使用 javascript)的应用程序。我想存储从 IN.ENV.auth.oauth_token 获得的访问 token ,因为我将使用它发布到用户的时间线。
但是当我使用此访问 token 发布到 Linkedin 时,出现“无效访问 token ”错误。 我是否使用了正确的访问 token ?如何获取访问 token 的正确方法?
这是我的代码:
$("#linkedin-connect").on('click',function(e){
e.preventDefault();
IN.UI.Authorize().place();
IN.Event.on(IN, "auth", OnLinkedInAuth);
return false;
});
function OnLinkedInAuth() {
console.debug("oauth token:" + IN.ENV.auth.oauth_token);
}
最佳答案
本次事件 IN.Event.on(IN, "auth", OnLinkedInAuth);
应该将一些数据传递给您的函数 OnLikedInAuth
如 sdk 文档中所示。
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: YOUR_API_KEY_HERE
authorize: true
onLoad: onLinkedInLoad
</script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
// Handle the successful return from the API call
function onSuccess(data) {
console.log(data);
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Use the API call wrapper to request the member's basic profile data
function getProfileData() {
IN.API.Raw("/people/~").result(onSuccess).error(onError);
}
作为该示例(在文档中可用)getProfileData
(类似于你的 OnLinkedInAuth
)返回一个 promise ,当它被解决时会给你一些 data
你需要阅读。在该对象中,您将找到可以存储 (LocalStorage) 和使用的 token
关于javascript - 使用 JavaScript SDK 获取 linkedin Access Token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31553463/