【发布时间】:2018-09-01 18:23:12
【问题描述】:
大家好,我目前正在编写一个小型 NodeJS 脚本,该脚本接受一个电子邮件地址,并试图找出特定电子邮件与哪些社交网络相关联。
这是我的代码:
const http = require('http');
const fetch = require('node-fetch');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
fetch('https://api.fullcontact.com/v3/person.enrich',{
method: 'POST',
headers: {
"Authorization": "Bearer {iWotm_auth_token}"
},
body: JSON.stringify({
"email": "bart@fullcontact.com",
"webhookUrl": "http://www.fullcontact.com/hook"
})
}).then(res=>{
res.json().then(json=>{console.log(json);});
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
这是我让服务器运行在 http://127.0.0.1:3000/ 的错误消息
{ status: 400, message: 'Access token supplied contains invalid characters' }
我正在使用最新的带有 Kali LInux 的 NodeJS 版本,以及 FullContact API。我的问题是,我确实通过运行 dos2unix 命令并消除了任何可能的空白来检查我的 api 密钥是否包含无效字符,那么错误 400 的原因是什么?
到目前为止我已经采取的步骤:
使用 bash 去除所有空格,使用 dos2unix 命令去除任何回车。然后查看jwt.io下的api key,看看我的api key是否有效。
你的回答会很棒。
【问题讨论】:
-
我在 FullContact api 文档中看到,使用 FullContact 进行身份验证的主要和推荐方法是使用名称为
X-FullContact-APIKey的扩展标头字段在 HTTP 请求标头中指定 API 密钥
标签: javascript node.js rest restful-authentication