I have been trying to get authorized on the ETrade API for a month now using Golang. I have been in contact with their technical support but they are useless. It takes a week for them to respond and sometimes the response is that they are sorry it is taking so long. The latest response just listed the api URLs again.
I have been using these libraries:
github.com/blbgo/etradeapi
github.com/dghubble/oauth1
They use Oauth1, so step one is to request a temporary token. Then you use that token to request the next token using a redirect. A couple of times, their website asked for my credentials to allow the app to access my account, but usually it goes right to the error message.
Here is my code:
func GetOauthToken(p *data.DaemonPage, w http.ResponseWriter, req *http.Request) error {
endpoint := oauth1.Endpoint{
RequestTokenURL: REQUEST_TOKEN_URL,
AuthorizeURL: AUTHORIZE_URL,
AccessTokenURL: ACCESS_TOKEN_URL,
}
config := oauth1.Config{
ConsumerKey: SANDBOX_API_KEY,
ConsumerSecret: SANDBOX_API_SECRET,
CallbackURL: "oob",
Endpoint: endpoint,
}
var err, err1 error
requestToken, requestSecret, err = config.RequestToken()
if err != nil {
return err
}
fmt.Println(requestToken, requestSecret)
authorizationURL, err1 := config.AuthorizationURL(requestToken)
if err1 != nil {
return err
}
values := authorizationURL.Query()
fmt.Println(values)
http.Redirect(w, req, authorizationURL.String(), http.StatusFound)
return nil
}
When I do the redirect, I get this message:
Due to a logon delay or other issue, your authentication could not be completed at this time. Please try again.
If anyone can offer suggestions, I would greatly appreciate it.