如何使用R语言RobinHood包登录并创建Robinhood对象?
Hey there, let's get you past that MFA error and create your RobinHood object successfully!
First, the core issue: Missing MFA code parameter
The latest version of the RobinHood package requires an MFA code for login (especially when using a new device, which triggers Robinhood's security check). The error you're seeing is just telling you that you need to include that mfa_code argument in your function call. Here's how to fix it:
- Trigger the MFA code: When you attempt to log in via the R package, Robinhood will automatically send a 6-digit verification code to the phone number linked to your account.
- Pass the code to the function: As soon as you receive the code, plug it into the
mfa_codeparameter like this:# Replace with your actual credentials and the code you received RH <- RobinHood::RobinHood( username = "your_real_username", password = "your_real_password", mfa_code = "123456" # Use the 6-digit code from your text message )
Do you need an incognito tab?
Short answer: No, you don't need to use an incognito browser tab for this. The R package's API login is independent of your browser sessions. The error you hit has nothing to do with browser cookies or sessions—it's purely about missing the required MFA parameter.
That said, if you run into issues like "unauthorized device" after entering the code, you can try logging into your Robinhood account once via a regular browser (to confirm the new device is allowed), then go back to running the R code. This usually resolves any lingering device authorization hiccups.
Bonus tip for smoother logins
If you're going to use this package regularly, consider switching your Robinhood MFA method to an authenticator app (like Google Authenticator or Authy). This way, you can generate codes instantly without waiting for text messages, which makes the login process faster and more reliable.
内容的提问来源于stack exchange,提问作者biglig

