Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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_Linkedin Api - Fatal编程技术网

Javascript LinkedIn登录,基本示例不起作用

Javascript LinkedIn登录,基本示例不起作用,javascript,linkedin-api,Javascript,Linkedin Api,我想添加LinkedIn登录到我的项目的可能性。我遵循了上给出的教程,最后得到了以下代码,这是该教程中非常基本的内容: <!-- linkedin login --> <script type="text/javascript" src="//platform.linkedin.com/in.js"> api_key: [MY_API_KEY] {~n} authorize: false {~n} onLoad: onLinkedInLoad {~n} &

我想添加LinkedIn登录到我的项目的可能性。我遵循了上给出的教程,最后得到了以下代码,这是该教程中非常基本的内容:

<!-- linkedin login -->
<script type="text/javascript" src="//platform.linkedin.com/in.js">
  api_key:   [MY_API_KEY] {~n}
  authorize: false {~n}
  onLoad: onLinkedInLoad {~n}
</script>

<!-- linkedin login play -->
<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);
    }

</script>

api_密钥:[我的api_密钥]{~n}
授权:false{~n}
onLoad:onLinkedInLoad{~n}
//设置事件侦听器,以便在完成身份验证后进行API调用
函数onLinkedInLoad(){
IN.Event.on(在“auth”中,getProfileData);
}
//处理API调用的成功返回
函数onSuccess(数据){
控制台日志(数据);
}
//处理来自API调用的错误响应
函数onError(错误){
console.log(错误);
}
//使用API调用包装器请求成员的基本配置文件数据
函数getProfileData(){
IN.API.Raw(“/people/~”).result(onSuccess).error(onError);
}
不要介意
{~n}
,因为我正在使用dust.js呈现页面,我需要它们将参数传递给LinkedIn脚本

因此,出现了登录按钮,这意味着LinkedIn能够正确连接到我的API密钥,但Chrome控制台给了我以下错误:
Uncaught错误:无法执行“onLinkedInLoad”。请为回调提供有效的函数。
。由于这是教程页面上给出的示例,我不知道它会有什么问题。即使我在.js中调用LinkedIn
之前声明了LinkedIn登录函数块,我也会得到同样的错误


我认为这是一个很容易发现的错误,但我无法真正判断我做错了什么。

发生这种情况的原因是您在head部分调用onLinkedInLoad(),并且如果您在多个页面上工作。它将在每个页面上被调用,即使它没有来自API调用的数据(或者只是您没有在出现此错误的页面上进行任何调用)

试试这个`

`
然后删除“onLoad:onLinkedInLoad{~n}”从第一次脚本调用开始

过了一段时间,我不确定这是否仍然相关/有效。我当时找到了一个不同的解决方案,但感谢您的输入。这是一个有效的解决方案。因为我和您一样被困在同一个问题上……然后找到了此页面……但它对我没有任何帮助……所以我想更新此页面..而且迟做总比不做好;)在.Event.on(在“auth”中,getProfiledata)中调用getProfiledata();
// Removing event listener by calling IN.Event.on() outside of 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);
}