[英]Cannot authorize with LinkedIn
我正在嘗試使用LinkedIn在我的網站上從用戶那里獲取名字,姓氏和電子郵件 。 這是我所做的:
在我的LinkedIn應用程序中,我已將默認范圍 (OAuth用戶協議)設置為:
我已將域正確添加到Javascript API域中 。 我沒有添加指向OAuth 2.0重定向URL的鏈接。 但是我不知道這是否是強制性的(以及插入哪條路徑)?
我還復制了我的API密鑰 (消費者密鑰)。
現在在我的HTML中:
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
lang: en_US
api_key: myapikey
scope: r_basicprofile r_emailaddress
</script>
<input class="apply-with-linkedin" type="button" value="Apply with LinkedIn" id="btn-linkedin-apply">
<script type="text/javascript">
jQuery('#btn-linkedin-apply').click(function (e) {
e.preventDefault();
e.stopPropagation();
IN.User.authorize(function ()
{
IN.API.Profile('me').fields([
'firstName',
'lastName',
'emailAddress'
]).result(function (profiles)
{
var me = profiles.values[0];
if (me.hasOwnProperty('firstName')) {
jQuery('#apply-form #input-firstname').val(me.firstName);
}
if (me.hasOwnProperty('lastName')) {
jQuery('#apply-form #input-lastname').val(me.lastName);
}
if (me.hasOwnProperty('emailAddress')) {
jQuery('#apply-form #input-email').val(me.emailAddress);
}
});
});
});
</script>
但是Cannot read property 'authorize' of undefined
當我單擊按鈕時,總是出現javascript錯誤Cannot read property 'authorize' of undefined
。 IN.User
未定義。
這可能是什么問題? ...
更新:
我在其中指定我的API密鑰的javascript代碼,...我從LinkedIn的“ JavaScript SDK入門”中復制而來。
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: [API_KEY]
onLoad: [ONLOAD]
authorize: [AUTHORIZE]
lang: [LANG_LOCALE]
</script>
您似乎在遇到與庫的異步性有關的問題。 我已經為您略微修改了“ 使用LinkedIn登陸 Javascript”示例中的示例代碼,但是我認為通過更加關注回調將解決您的問題,以便您知道a)加載了庫,b)API呼叫已成功完成-在嘗試訪問任何結果數據之前:
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: YOUR_API_KEY_HERE
authorize: true
scope: r_basicprofile r_emailaddress
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) {
// Pre-populate your form fields here once you know the call
// came back successfully
}
// 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/~:(firstName,lastName,emailAddress)").result(onSuccess).error(onError);
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.