Vb.net 向Google gmail API发出令牌请求时请求错误400

Vb.net 向Google gmail API发出令牌请求时请求错误400,vb.net,oauth,google-api,token,bad-request,Vb.net,Oauth,Google Api,Token,Bad Request,我遵循此文档提出令牌请求 在第一步中,它工作良好。我可以得到一个身份验证码。 在第二步中,我遇到了400个错误请求的问题。我两天来一直在寻找这个问题的答案,但我无法解决这个问题。 我像文档一样设置了所有属性,但这并不重要: POST /oauth2/v3/token HTTP/1.1 Host: www.googleapis.com Content-Type: application/x-www-form-urlencoded code=4/v6xr77ewYqhvHSyW6UJ1w7jKwA

我遵循此文档提出令牌请求

在第一步中,它工作良好。我可以得到一个身份验证码。 在第二步中,我遇到了400个错误请求的问题。我两天来一直在寻找这个问题的答案,但我无法解决这个问题。 我像文档一样设置了所有属性,但这并不重要:

POST /oauth2/v3/token HTTP/1.1
Host: www.googleapis.com
Content-Type: application/x-www-form-urlencoded

code=4/v6xr77ewYqhvHSyW6UJ1w7jKwAzu&
client_id=8819981768.apps.googleusercontent.com&
client_secret=your_client_secret&
redirect_uri=https://oauth2-login-demo.appspot.com/code&
grant_type=authorization_code
这是我的密码:

    postData.Clear()
    ' code is the authentication code in the first request
    postData.Add("code=" + code)
    postData.Add("client_id=###############.apps.googleusercontent.com")
    postData.Add("client_secrect=####################")
    postData.Add("redirect_uri=urn:ietf:wg:oauth:2.0:oob")
    postData.Add("grant_type=authorization_code")

    Dim data As String = String.Join("&", postData.ToArray())
    Dim request As HttpWebRequest = HttpWebRequest.Create("https://www.googleapis.com/oauth2/v3/token")
    Dim byteData() As Byte = Encoding.UTF8.GetBytes(data)

    request.Host = "www.googleapis.com"
    request.Method = WebRequestMethods.Http.Post
    request.ProtocolVersion = HttpVersion.Version11
    request.ContentType = "application/x-www-form-urlencoded"
    request.ContentLength = byteData.Length

    Dim dataStream As Stream = request.GetRequestStream()
    dataStream.Write(byteData, 0, byteData.Length)
    dataStream.Close()        

    Dim response As HttpWebResponse = request.GetResponse()
    Dim reader As Stream = response.GetResponseStream()
    response.Close()

谢谢你的回答

我刚发现一个bug。这是一只愚蠢的虫子。我输入了客户机密的客户机密。我真不敢相信我花了两天的时间来修复这个错误