vba中的MSXML2.XMLHTTP60对象不工作

vba中的MSXML2.XMLHTTP60对象不工作,vba,ms-access,paypal,Vba,Ms Access,Paypal,我编写了一个程序来获取令牌,以便在MicrosoftAccess中使用PayPalAPI 但是xmlhttp.send行“grant\u type=client\u credentials”无法正常工作。有时我会收到两种类型的错误消息,有时它不会出错 请帮我修复这个程序,哦,告诉我这个错误的原因 Dim xmlhttp As New MSXML2.XMLHTTP60 Dim tempStr As String Dim requestUrl_2 As String Dim requestMet

我编写了一个程序来获取令牌,以便在MicrosoftAccess中使用PayPalAPI

但是xmlhttp.send行“grant\u type=client\u credentials”无法正常工作。有时我会收到两种类型的错误消息,有时它不会出错

请帮我修复这个程序,哦,告诉我这个错误的原因

Dim xmlhttp As New MSXML2.XMLHTTP60

Dim tempStr As String
Dim requestUrl_2 As String

Dim requestMethod As String

Dim encodeData As String

requestUrl_2 = "https://api.sandbox.paypal.com/v1/oauth2/token"

requestMethod = "POST"
encodeData = Base64EncodeString(ClientID & ":" & ClientSecret)

xmlhttp.Open requestMethod, requestUrl_2, False

xmlhttp.setRequestHeader "Accept", "application/json"
xmlhttp.setRequestHeader "Accept-Language", "en_US"
xmlhttp.setRequestHeader "Authorization", "Basic " & encodeData

xmlhttp.send "grant_type=client_credentials"
' ------------------------------------------------------------------------------------------------------

If xmlhttp.status = 200 Then
    tempStr = Split(Split(xmlhttp.responseText, "access_token")(1), "token_type")(0)
    
    tempStr = Left(tempStr, Len(tempStr) - 3)
    
    tempStr = Right(tempStr, Len(tempStr) - 3)
    
    MsgBox tempStr
Else
    MsgBox "Error! Response status returned " & xmlhttp.status
End If

Set xmlhttp = Nothing
当我第一次运行应用程序并调用此过程时,在xmlhttp.send“grant_type=client_credentials”行上出现错误:“指定资源的下载失败。”

之后,我将错误行的代码更改为“xmlhttp.send”,并得到一个错误。xmlhttp.responseText:{“错误”:“不支持的授权类型”,“错误描述”:“授权类型为空”}

之后,我再次使用xmlhttp.send行“grant\u type=client\u credentials”运行该过程,并且不再出现错误。我可以无休止地使用此过程(在我重新启动应用程序之前)

我编写了一个过程来获取令牌,以便在Microsoft Access中使用PayPal API。
如果您使用的是Access,而不是Excel,请更新您的标记。