我正在运行meteor.js 并已全局安装npm 包node-linkedin
https://www.npmjs.com/package/node-linkedin
我已经用linkedin注册了我的应用程序,这意味着我有我的api密钥、密钥和oAuth重定向url到localhost:3000
我的应用程序当前显示“登录”linkedIn 按钮,用户在其中授予我的应用程序访问用户完整个人资料的权限。根据linkedIn javascript API docs,该onLinkedInAuth()对象(在成功验证后运行)包含用户的linkedin id。
Accounts.createUser当用户通过身份验证并将来自 onLinkedInAuth() 对象的id存储在用户集合中时,如何创建用户帐户?
服务器.js
var Linkedin = Npm.require('node-linkedin')('api', 'secret', 'I-PUT-REDIRECT-URL-HERE');
如何使用 npm 包https://www.npmjs.com/package/node-linkedin(参见标题 oAuth 2.0 下)发出获取请求,该包将用户重定向到linkedins 授权对话框并随后检索访问令牌。
HTML:
<head>
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
api_key: *MY_API_KEY*
onLoad: onLinkedInLoad
authorize: true
</script>
<script type="text/javascript">
// Runs when the JavaScript framework is loaded
function onLinkedInLoad() {
IN.Event.on(IN, "auth", onLinkedInAuth);
}
// Runs when the viewer has authenticated
function onLinkedInAuth() {
IN.API.Profile("me")
.result( function(me) {
var id = me.values[0].id;
// AJAX call to pass back id to your server
});
}
// Runs when the Profile() API call returns successfully
function displayProfiles(profiles) {
member = profiles.values[0];
document.getElementById("profiles").innerHTML =
"<p id=\"" + member.id + "\">Hello " + member.firstName + " " + member.lastName + "</p>";
}
</script>
</head>
<template name="parent"> //layout template
<!-- Displays a button to let the viewer authenticate -->
<script type="IN/Login" data-onAuth="onLinkedInAuth"></script>
<!-- Placeholder for the greeting -->
<div id="profiles"></div>
</template>