我试图用令牌和我收到的#34; redirect_uri_mismatch"交换授权代码。 现在,在控制台中编写的所有URL都与我在POST Web请求正文中发送的redirect_url相同,
这是使用授权码接收响应后的代码(vb):
Dim strCode As String = HttpContext.Current.Request.QueryString("code")
Dim getTokenBody As String
getTokenBody = "code=" & HttpContext.Current.Server.UrlEncode(strCode) & _
"&client_id=" & HttpContext.Current.Server.UrlEncode(AppStaticData.Config.GoogleClientID.Value) & _
"&client_secret=" & HttpContext.Current.Server.UrlEncode(AppStaticData.Config.GoogleClientSecret.Value) & _
"&redirect_uri=" & HttpContext.Current.Server.UrlEncode("http://localhost:53706/user/authenticate") & _
"&scope=" & _
"&grant_type=authorization_code"
Dim buffer As Byte() = Encoding.ASCII.GetBytes(getTokenBody)
Dim url = "https://accounts.google.com/o/oauth2/token"
Dim request As HttpWebRequest = WebRequest.Create(url)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = buffer.Length
Dim strm As Stream = request.GetRequestStream()
strm.Write(buffer, 0, buffer.Length)
strm.Close()
Try
Dim res As HttpWebResponse = request.GetResponse()
Catch ex As WebException
Dim a = ex.Response
Dim wr As Net.HttpWebResponse = DirectCast(a, Net.HttpWebResponse)
Dim s = New StreamReader(wr.GetResponseStream()).ReadToEnd
End Try
答案 0 :(得分:0)
您需要将返回的uri添加到应用程序的开发者控制台中的重定向uri列表中。
(如果屏幕截图不起作用,则为链接https://www.dropbox.com/s/lgjm1zgk8qeft00/console.png?dl=0)
在屏幕截图的底部,您会看到编辑设置。点击它并将您的uri添加到AUTHORIZED REDIRECT URIS
部分。