首页 > 解决方案 > nodejs robinhood api登录

问题描述

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

   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}}}

标签: apiauthenticationtoken

解决方案


如果使用 api,Robinhood 最近需要启用 2fa。它在请求正文的详细信息中提到。

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

继续打开它,然后您可以使用此代码段访问 api

let Robinhood = require('robinhood')(credentials, function(data) {
    if (data && data.mfa_required) {
        var mfa_code = ""; //Notice this is blank. 
        Robinhood.set_mfa_code(mfa_code, () => {
            console.log(Robinhood.auth_token());
            Robinhood.positions((error, response, body) => {
                console.log(body);
            })
        })
    }
})

一旦您提出请求,您将收到一个错误,但 2fa 质询将发送到您设置帐户的任何地方。收到 2fa 代码后,设置 mfa_code 并重新运行代码段。一旦您使用有效的 2fa 代码再次运行该代码段,那么您已经成功登录。复制授权令牌,您可以使用它而无需再次通过 2fa,我相信 24 小时


推荐阅读