nodejs robinhood api 登录

我正在尝试登录 robinhood API,我在应用程序中关闭了 2fa 和 sms,但仍然出现错误,下面是否看起来正确,或者 robinhood 在关闭 2fa 时更新较慢。

   var credentials = {
        username: '*****',
        password: '*****'
    };
    var Robinhood = require('robinhood')(credentials, function(){
        console.log(Robinhood.auth_token());
            //      <authenticated alphanumeric token>
    })

错误信息

Error: token not found {"statusCode":400,"body":{"detail":"Request blocked, challenge type required.","accept_challenge_types":{"sms":"SMS"}},"headers":{"date":"Mon, 24 May 2021 22:44:07 GMT","content-type":"application/json","content-length":"93","connection":"close","server":"openresty","allow":"POST, OPTIONS","x-robinhood-api-version":"0.0.0","content-security-policy":"default-src 'none'","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block","access-control-allow-origin":"https://robinhood.com","vary":"Origin","trace-uuid":"56ccb9cc-8bca-4dbd-be6f-4a6d86171354"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"api.robinhood.com","port":443,"hostname":"api.robinhood.com","hash":null,"search":null,"query":null,"pathname":"/oauth2/token/","path":"/oauth2/token/","href":"https://api.robinhood.com/oauth2/token/"},"method":"POST","headers":{"Host":"api.robinhood.com","Accept":"*/*","Accept-Encoding":"gzip, deflate","Referer":"https://robinhood.com/","Origin":"https://robinhood.com","content-type":"application/x-www-form-urlencoded","content-length":214}}}
点赞
用户5808465
用户5808465

Robinhood最近要求启用二次验证(2FA)来使用API。 这在请求正文的详细信息中提到。

"detail":"Request blocked, challenge type required.","accept_challenge_types":{"sms":"SMS"}} 

现在你需要打开2FA才能使用这段代码访问API

let Robinhood = require('robinhood')(credentials, function(data) {
    if (data && data.mfa_required) {
        var mfa_code = ""; //注意此时mfa_code是空的。
        Robinhood.set_mfa_code(mfa_code, () => {
            console.log(Robinhood.auth_token());
            Robinhood.positions((error, response, body) => {
                console.log(body);
            })
        })
    }
})

一旦你发出请求,你会收到一个错误,但2FA会被发送到您账户的任何需要设置的设备上。 一旦您收到2FA代码,请设置mfa_code并重新运行代码。 成功运行了一遍并使用有效的 2FA 代码重新运行代码之后,您将成功登录。 复制授权令牌,您可以在使用24小时后不需要再次经历2FA的情况下使用它。

2021-05-31 19:36:42