我在 Julia 工作,并尝试连接到 Schwab API。这是我的代码:
authUrl = "https://api.schwabapi.com/v1/oauth/authorize?client_id=$clientID&redirect_uri=https://127.0.0.1"
;
println(authUrl)
println("redirect url")
returnedLink = readline()
;
code = returnedLink[findfirst("code=", returnedLink).stop + 1:findfirst("%40", returnedLink).start - 1] * "@";
encode = base64encode("$clientID:$secret")
headers = Dict(
"Authorization" => "Basic $encode",
"Content-Type" => "application/x-www-form-urlencoded"
)
data = [
"grant_type" => "authorization_code",
"code" => code,
"redirect_uri" => "https://127.0.0.1"
]
;
response = HTTP.post("https://api.schwabapi.com/v1/oauth/token", headers=headers, form=data)
它给了我这个错误消息:
HTTP.Exceptions.StatusError(400, "POST", "/v1/oauth/token", HTTP.Messages.Response:
"""
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: 98
Cache-Control: no-store
Pragma: no-cache
Expires: -1
Access-Control-Allow-Headers: *, X-Authorization
Access-Control-Max-Age: 3628800
Access-Control-Allow-Methods: GET, POST, OPTIONS
Date: Sun, 02 Jun 2024 13:28:57 GMT
Connection: close
Strict-Transport-Security: max-age=30
{"error":"invalid_grant","error_description":"Missing parameter grant_type"}
""")
即使我在上面指定了授权类型,为什么还是会收到无效授权错误?