gpt4 book ai didi

javascript - Node js 将返回的 API key 存储为变量

转载 作者:行者123 更新时间:2023-12-03 04:08:25 25 4
gpt4 key购买 nike

我是 Node 新手,正在尝试使用 A node.js library for the Pardot API

我将我的userKeyemailpassword传递给pardot,这会返回我的api_key

我使用以下代码进行身份验证,然后当我运行 Node 服务器时,我可以看到 api_key 被传回。

如何将该 api_key 存储为变量,然后用于将数据发布到 API?

我的 Node 代码

var nodePardot = require('node-pardot');

// Create client using email, password and user_key
nodePardot.PardotAPI({
userKey: 'kyujk',
email: 'uu.uuy@uu.co.uk',
password: 'uit.09',
DEBUG: true
}, function(err, client) {
// Authentication completed
console.log('Authentication completed');

// gets api key
var api_key = api_key;
console.log('key',api_key);
});

我的控制台输出

[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
Server started! At http://localhost:8080
Initializing node-pardot in DEBUG mode
params {"email":"bhyuyten.jj@jyj.co.uk","password":"tyjt.09","user_key":"yjty76","format":"json"}
uri https://pi.pardot.com/api/login/version/3?email=ss.jyj%s.co.uk&password=tyjt.09&user_key=yjty76&api_key=&format=json
parsedResponse {"@attributes":{"stat":"ok","version":1},"api_key":"878074492492dhjjk67u","version":4}
Authentication completed
key undefined
parsedResponse {"@attributes":{"stat":"ok","version":1},"api_key":"878074492492dhjjk67u","version":4}


var nodePardot = require('node-pardot');

// Create client using email, password and user_key
nodePardot.PardotAPI({
userKey: 'fdgr',
email: 'rg.gg@gg.co.uk',
password: 'dfherg',
DEBUG: true
}, function(err, client) {
// Authentication completed
console.log('Authentication completed');

// gets api key
var api_key = api_key;
console.log('key',api_key);
});

最佳答案

查看node-pardot的来源herehere ,看起来 API key 位于 client.apiKey

此外,您应该始终检查 Nodejs 风格的回调函数中的错误条件!

nodePardot.PardotAPI({
userKey: '...',
email: '...',
password: '...',
DEBUG: true
}, function(err, client) {
if(err){
// Authentication failed
// handle error
console.error("Authentication Failed", err)
} else {
// Authentication successful
// gets api key
var api_key = client.apiKey;
console.log("Authentication successful", api_key);
}
});

附注您永远不应该在公共(public)论坛和 QA 网站上发布 API key 和凭据

关于javascript - Node js 将返回的 API key 存储为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44440680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com