2016-10-20 79 views
1

是否可以通過提供憑據 - 用戶電子郵件和密碼來獲取訪問令牌以使用node-linkedin包?我想要做的是一個命令行應用程序,它可以讓api調用linkedin並將結果寫入文本文件。因此,我不會向客戶端發送任何api調用結果。使用電子郵件和密碼獲取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錯誤的請求。

+0

感謝您的回答!目前我無法複製此內容,因此如果有人發現此答案有用,我會將其標記爲最有幫助! – mcmxc

+0

@mcmxc你是說這些'auth'端點適合你嗎? – chovy

+0

實際上我不可能檢查出來,所以你的答案按照你的預期工作並解決了我的問題,我會將你的答案標記爲已接受。 – mcmxc

相關問題