Json 通过脚本登录时出现Textnow API错误

Json 通过脚本登录时出现Textnow API错误,json,api,promise,Json,Api,Promise,尝试使用正确的用户名和密码通过API登录textnow时,会发生以下错误: UnhandledPromiseRejectionWarning: Error: 401 Unauthorized at _response.transport.request.then (E:\nodejs\node_modules\snekfetch\src\index.js:193:21) at process._tickCallback (internal/process/next_tick.js:68:7) (

尝试使用正确的用户名和密码通过API登录textnow时,会发生以下错误:

UnhandledPromiseRejectionWarning: Error: 401 Unauthorized
at _response.transport.request.then (E:\nodejs\node_modules\snekfetch\src\index.js:193:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:19732) UnhandledPromiseRejectionWarning: Unhandled promise rejection.            
This error originated either by throwing inside of an async function without
a catch block, or by rejecting a promise which was not handled with .catch().
(rejection id: 2)            
下面是我正在使用的API中的代码:

module.exports.textnowLogin = (email, password) => {
   return new Promise((resolve, reject) => {
   let json = { "password": password, "username": email };
   let queryEndpoint = "sessions?client_type=TN_ANDROID";
   let signature = md5(`${tnSignatureKey}POST${queryEndpoint}${JSON.stringify(json)}`);

    snekfetch.post(`https://api.textnow.me/api2.0/${queryEndpoint}&signature=${signature}`)
    .set("Content-Type", "application/json")
    .send(json)
    .then((result) => {
      return resolve(result.body);
    }).catch(reject);
  });
};
下面是我如何在js文件中使用此方法的一个示例:

const textNow = require('textnow-api');
textNow.login(username, password).then(client => {
  console.log(`Logged in as ${client.username}`);
});`
这肯定是服务器端的问题,不是吗?Textnow的结尾一定出了问题。我能做些什么来避免这种情况

编辑:
const snekfetch=require(“snekfetch”),
md5=要求(“md5”),
tnSignatureKey=“f8ab2ceca9163724b6d126aea9620339”

这把钥匙是从哪里来的?如果生成一个新的,那么授权错误可能会得到解决


作为旁注,另一个潜在的问题可能是客户端类型被设置为ANDROID,我正在尝试使用iOS帐户登录。然而,每当我尝试使用Android帐户登录时,就会收到400个错误请求,比如Textnow无法识别该帐户的凭据

代码中可能还有其他错误,但第一个错误是创建了额外的承诺。这是一个解决这个问题的代码版本,它要么可以工作,要么调试起来更简单

module.exports.textnowLogin = (email, password) => {
  let json = { "password": password, "username": email };
  let queryEndpoint = "sessions?client_type=TN_ANDROID";
  let signature = md5(`${tnSignatureKey}POST${queryEndpoint}${JSON.stringify(json)}`);

  let url = `https://api.textnow.me/api2.0/${queryEndpoint}&signature=${signature}`;
  return snekfetch.post(url).set("Content-Type", "application/json").send(json).then(result => {
    return result.body;
  });
};

谢谢,代码看起来更简洁易读。我对JavaScript没有太多经验,但我将尝试调试,并返回这里,给出可能发生的情况的结果,因为401未经授权的错误仍在发生。@BisquickQuick 401错误就是这类错误的进展。这与OP错误不同,可能与服务器出于安全原因拒绝请求有关(可能与该签名的形成有关。我认为OP中的代码结构阻止了您查看(以及调试)您的代码与服务器预期之间的实际错误我认为正在使用的tnSignatureKey可能是导致问题的原因。变量设置在顶部,可能提供的密钥在Textnow端不再被允许或识别。我将使用API中提供的密钥编辑帖子