【发布时间】:2022-01-24 18:58:21
【问题描述】:
我正在尝试通过 Oauth2.0 从合作伙伴的 api 接收访问令牌。 当我使用 CURL 时,我得到了令牌,但不在我的 VBA 脚本中。 我收到此错误:
{"error":"invalid_request","error_description":"Missing grant type"}
成功的CURL方式是这样的:
curl -X POST -H "client_id:xxx" -u xxx:xxx"https://my.arrow.com/api/security/oauth/token" -d "grant_type=client_credentials"
我试图以不同的位置和拼写发送grant_type=client_credentials(在正文中,作为 SetRequestHeader、grant_type=client_credentials 或 grant_type:client_credentials 或 grant_type、client_credentials)没有任何帮助,总是同样的错误。
这是 API 的文档:https://my.arrow.com/more/developers/#section/Access-Token
Public Function API_MyArrow_Artikel(artikelBez) As String
Dim objHTTP As Object
Dim strHead As String, strClientId As String, strClientSecret As String, strBody As String
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
strClientId = "xxx"
strClientSecret = "xxx"
strUrl1 = "https://my.arrow.com/api/security/oauth/token"
strHead = strClientId & ":" & strClientSecret
lngADRNR = 674
objHTTP.Open "POST", strUrl1, False
objHTTP.SetRequestHeader "application", "x-www-form-urlencoded"
objHTTP.SetRequestHeader "client_id", strClientId
objHTTP.SetRequestHeader "client_secret", strClientSecret
objHTTP.SetRequestHeader "Authorization", "Basic " + Base64Encode(strHead)
'objHTTP.setRequestHeader "grant_type", "client_credentials"
objHTTP.SetTimeouts 10000, 10000, 10000, 10000 'Timeout (in milliseconds) to wait for timeout in each request phase (Resolve, Connect, Send, Receive)
objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.Send "grant_type=client_credentials"
API_MyArrow_Artikel = objHTTP.responseText
End Function
【问题讨论】: