Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法使用LinkedIn进行授权_Javascript_Jquery_Oauth_Oauth 2.0_Linkedin - Fatal编程技术网

Javascript 无法使用LinkedIn进行授权

Javascript 无法使用LinkedIn进行授权,javascript,jquery,oauth,oauth-2.0,linkedin,Javascript,Jquery,Oauth,Oauth 2.0,Linkedin,我正试图从LinkedIn网站上的一位用户那里获得名字、姓氏和电子邮件。这就是我所做的: 在我的LinkedIn应用程序中,我已将默认范围(OAuth用户协议)设置为: r_基本配置文件 r_联系人信息 w_份额 电子邮件地址 我已将我的域正确添加到Javascript API域中。我没有添加到OAuth 2.0重定向URL的链接。但我不知道这是否是强制性的(以及插入哪条路径) 我还复制了我的API密钥(消费者密钥) 现在,在我的HTML中,我有: <script type="text

我正试图从LinkedIn网站上的一位用户那里获得名字、姓氏和电子邮件。这就是我所做的:

在我的LinkedIn应用程序中,我已将默认范围(OAuth用户协议)设置为:

  • r_基本配置文件
  • r_联系人信息
  • w_份额
  • 电子邮件地址
我已将我的域正确添加到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>

您可能只是遇到了库的异步性问题。我已经为您稍微修改了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>

api_密钥:这里是您的api_密钥
授权:正确
范围:r_基本配置文件r_电子邮件地址
onLoad:onLinkedInLoad
//设置事件侦听器,以便在完成身份验证后进行API调用
函数onLinkedInLoad(){
IN.Event.on(在“auth”中,getProfileData);
}
//处理API调用的成功返回
函数onSuccess(数据){
//一旦知道呼叫,请在此预先填充表单字段
//成功地回来了
}
//处理来自API调用的错误响应
函数onError(错误){
console.log(错误);
}
//使用API调用包装器请求成员的基本配置文件数据
函数getProfileData(){
IN.API.Raw(“/people/~:(firstName,lastName,emailAddress)”).result(onSuccess).error(onError);
}

@JeremyThille:我已经为我的主题添加了一个更新。你能看一看吗?@JeremyThille,那他们为什么把这个放在入门主题??Jeremy-文档是正确的,你也正确,这显然不是标准的Javascript符号。LinkedIn使用新行和名称:值对解析标签中的内容,如前所述。
<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>