不良请求400向Google Gmail API提出令牌请求时



我遵循此文档以做出令牌请求https://developers.google.com/indesity/protocols/oauth2install2installedapp

在第一步中,它可以正常工作。我可以获得身份验证代码。在第二步中,我有400个不良请求的问题。我已经为这个问题找到了2天的答案,但是我无法解决问题。我设置了像文档一样的所有属性,但是没关系:

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()

感谢您的回答!

我刚找到一个错误。这是一个愚蠢的错误。我键入client_secter_secret的client_secrect intects。我不能相信我花了2天的时间来解决此错误。

相关内容

  • 没有找到相关文章

最新更新