如何修复vba中的“ {{error:“ invalid_request”,“ error_description”:“未在请求中指定授予类型”}“?

时间:2019-06-17 09:33:24

标签: excel vba api winhttprequest

我想通过api将带有vba的excel工作表连接到在线调查表。如果从测试人员填写调查表,我将获得状态。

我知道一些python和matlab,但这是我的第一个vba项目。但是现在我在授予类型上遇到了一些错误。尝试了很多论坛。

{“错误:” invalid_request”,“错误描述”:“未在请求中指定授予类型”}

我正在使用Microsoft提供的2016年excel版本“家庭和企业版”

Sub API_test()

' API_test Makro

 Dim winHttpReq As Object

    Dim Username As String
    Dim Password As String
    Dim PasswordnUsername As String
    Dim argumentString As String

    Username = "xxxx" 'client_id
    Password = "xxxx" 'client_secret



    PasswordnUsername = Password & ":" & Username

    argumentString = "?grant_type=client_credentials&client_id=Username&client_secret=Password"

    'Set winHttpReq = CreateObject("Microsoft.XMLHTTP")
    Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")


    winHttpReq.Open "POST", url, False

    winHttpReq.SetRequestHeader "client_id", Username
    winHttpReq.SetRequestHeader "client_secret", Password
    winHttpReq.SetRequestHeader "response_type", "code"
    winHttpReq.SetRequestHeader "grant_type", "client_credentials"


    winHttpReq.Send (argumentString) '"grant_type=client_credentials"

    MsgBox winHttpReq.StatusText
    MsgBox winHttpReq.responseText

    GetData = winHttpReq.responseText


    results = "HallO!"




    MsgBox results
    End Sub

我想从winHttpReq获得成功的回复

提前谢谢

0 个答案:

没有答案