【问题标题】:Error Unsupported Grant Type错误不支持的授权类型
【发布时间】:2017-06-02 13:22:10
【问题描述】:

我正在尝试使用 MS Excel VBA 连接到 API。登录需要的参数是授权类型、用户名和密码。

我想出了下面的代码,但是我得到了错误:

{"error":"unsupported_grant_type"}

谁能告诉我我在哪里做错了?

Sub test()

Dim objHttp As Object
Dim json As String
Dim user, password As String

user = "user1"
password = "password1"
json = "{""grant_type"":""password"",""username"":""" & user & """,""password"":""" & password & """}"

MsgBox json

Dim result As String

Set objHttp = CreateObject("MSXML2.XMLHTTP")
url = "http://dummywebsite.com"
objHttp.Open "POST", url, False

objHttp.SetRequestHeader "Content-type", "application/json"
objHttp.Send (json)
result = objHttp.ResponseText

MsgBox result

End Sub

代码实际上可以工作,这是由于使用另一个用户帐户测试后的用户权限。

【问题讨论】:

  • 你定义了“grant_type”吗?
  • 你的意思是在我的代码或后端?我已将授权类型直接输入到我的代码中。
  • 我刚刚看到定义了用户和密码,但没有 grant_type,如果我误解了,请见谅。
  • grand_type 是密码,我把它放在代码中。显然代码正在运行,我借了另一个用户帐户来尝试。将就用户权限与管理员联系。谢谢@Solar Mike

标签: vba excel api xmlhttprequest


【解决方案1】:

试试:

标题: - 内容类型:application/x-www-form-urlencoded - 接受字符集:UTF-8 - 授权:[您的授权码]

身体: 用户名=[用户名]&密码=[密码]&grant_type=密码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多