javascript - LinkedIn 登录基本示例不起作用

标签 javascript linkedin-api

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

<!-- 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>

不要介意 {~n},因为我正在使用 dust.js 呈现页面,我需要它们将参数传递给 LinkedIn 脚本。

所以,登录按钮出现了,这意味着 LinkedIn 能够正确连接到我的 API key ,但是 Chrome 控制台给我以下错误:Uncaught Error: Could not execute 'onLinkedInLoad'。请提供有效的回调函数。。由于这是教程页面上给出的 示例,我不知道它有什么问题。即使我在调用 LinkedIn in.js 之前声明了 LinkedIn 登录函数 block ,我也会遇到同样的错误。

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

最佳答案

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

试试这个`

// 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);
}

` 是的,从第一个脚本调用中删除“onLoad: onLinkedInLoad {~n}”

关于javascript - LinkedIn 登录基本示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34117147/

相关文章:

Javascript 从页面上的任何文本输入/文本区域获取选定的文本

c# - LinkedIn - 是否可以在我的应用程序的用户组中发帖?

linkedin-api - Linkedin API 公司分享 updateUrl 返回无效链接

javascript - 如何在通过 Oauth2 从 LinkedIn 获取访问 token 后获取用户个人资料数据

java - 找不到 ImportLinkedInProfile 的 jar

javascript - 通过 bootstrap 使用 jquery popover 进行 Rails CRUD

javascript - 需要帮助设置 Node/Knex 迁移

javascript - 如何生成 404 错误而不是强制转换错误

javascript - 如何在 React material-ui 日期选择器中格式化日期?

linkedin - 新的LinkedIn API策略更改后访问r_fullprofile