交换访问令牌时,Google OAuth2错误400

时间:2012-05-22 05:54:24

标签: api oauth

使用以下VBA代码在Google API中为访问令牌交换有效的授权令牌时,我收到“400 Bad Request”错误。任何人都可以解释为什么,我一直在努力与这一个超过一个星期。

Dim http As MSXML2.XMLHTTP
Dim sUrl As String
Dim sUrlHeader As String
Dim svarbody As String

Set http = New MSXML2.XMLHTTP

sUrl = "https://accounts.google.com/o/oauth2/token? HTTP/1.1"

http.Open "POST", sUrl


http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

svarbody = "code=4%2FXAjmXiUlBXUAUGCnMvNKsxdyuJEJ.8kfzzrqo3wwTuJJVnL49Cc9gML_lbgI&" & _
"client_id=50487549202#-q27v28nvhmjhc0uobq35tjn09lhrh47r.apps.googleusercontent.com&" &         _
"redirect_uri=http%3A%2F%2Flocalhost&" & _
"scope=https%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds&" & _
"client_secret=<secret delete for this post>&" & _
"grant_type=authorization_code"

http.send svarbody

Me.Text3 = http.status & vbCrLf & http.statusText & vbCrLf & http.responseText

3 个答案:

答案 0 :(得分:0)

这是一个非常常见的问题。您可以尝试通过许多方法和测试来解决它......但是......

首先应该尝试的是:

更新您的服务器/计算机WINDOWS CLOCK,使用time.nist.gov(或兄弟)。双击Windows小时 - 日期(在屏幕底部,以这种方式更改Internet时间)

SntsDev

答案 1 :(得分:0)

根据我在VBA中使用Oauth 2.0的经验,当您多次使用代码来请求令牌时会发生此错误。我根据文档和经验使用的使用顺序是: 访问GET https://accounts.google.com/o/oauth2/auth 一次以获取代码 访问POST https://accounts.google.com/o/oauth2/token 一次以获取令牌 之后,只要它有效就使用令牌

答案 2 :(得分:0)

您可能需要在自己的Google帐户中设置结算信息。

相关问题