【问题标题】:Get an access token to Linkedin API using email and password使用电子邮件和密码获取 Linkedin API 的访问令牌
【发布时间】:2017-01-31 04:04:24
【问题描述】:

是否可以通过提供凭据 - 用户电子邮件和密码来获取访问令牌以使用 node-linkedin 包?我想做的是一个命令行应用程序,它可以对linkedin进行api调用并将结果写入文本文件。因此,我不会向客户端发送任何 api 调用结果。

【问题讨论】:

    标签: node.js access-token linkedin-api


    【解决方案1】:

    我一直在尝试做同样的事情。

    simple-oauth2 模块有一种通过密码登录的方法,但我似乎无法让它工作。

    https://www.npmjs.com/package/simple-oauth2

    // Set the configuration settings
    const credentials = {
      client: {
        id: '<client-id>',
        secret: '<client-secret>'
      },
      auth: {
        tokenHost: 'https://api.linkedin.com',
        authorizePath: 'https://api.linkedin.com/uas/oauth/requestToken',
        tokenPath: 'https://api.linkedin.com/uas/oauth/accessToken'
      }
    };
    
    // Initialize the OAuth2 Library
    const oauth2 = require('simple-oauth2').create(credentials);
    
    // Get the access token object.
    const tokenConfig = {
      username: 'username',
      password: 'password' 
    };
    
    // Callbacks
    // Save the access token
    oauth2.ownerPassword.getToken(tokenConfig, (error, result) => {
      if (error) {
        return console.log('Access Token Error', error.message);
      }
    
      const token = oauth2.accessToken.create(result);
    });
    

    我不确定这些端点是否正确:

      auth: {
        tokenHost: 'https://api.linkedin.com',
        authorizePath: 'https://api.linkedin.com/uas/oauth/requestToken',
        tokenPath: 'https://api.linkedin.com/uas/oauth/accessToken'
      }
    

    我收到 400 错误请求。

    【讨论】:

    • 感谢您的回答!目前我无法重现这个,所以如果有人觉得这个答案有用,我会把它标记为最有帮助的!
    • 实际上我不可能检查出来,所以你的答案对你来说符合预期并解决了我的问题,我会将你的答案标记为已接受。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 2017-05-22
    • 1970-01-01
    • 2021-05-07
    • 2017-01-07
    • 1970-01-01
    相关资源
    最近更新 更多