c# - 如何使用 Google.Apis.Oauth2.v2 获取用户信息 - 授权错误 Error 400: redirect_uri_mismatch
问题描述
我正在使用:https ://newbedev.com/access-user-info-using-google-apis-for-net
vb.net nuget = Google.Apis.Oauth2.v2
我不想使用 MVC。只是一个简单的 1 页 vb asp.net Web 应用程序
错误= 授权错误错误 400:redirect_uri_mismatch
您无法登录此应用,因为它不符合 Google 的 OAuth 2.0 政策。
如果您是应用开发者,请在 Google Cloud Console 中注册重定向 URI。
Dim urlOAuth As String = "https://accounts.google.com/o/oauth2/auth"
Dim urlGetToken As String = "https://accounts.google.com/o/oauth2/token"
这里我想获取用户信息
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim secrect = New ClientSecrets() With {
.ClientId = clientID,
.ClientSecret = clientSecret
}
Dim scopes = {Oauth2Service.Scope.UserinfoEmail, Oauth2Service.Scope.UserinfoProfile}
Dim credential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(secrect, scopes, "user", CancellationToken.None).Result
Dim oauthSerivce = New Oauth2Service(New BaseClientService.Initializer() With {
.HttpClientInitializer = credential,
.ApplicationName = "MyApplicationName"
})
Dim userInfo = oauthSerivce.Userinfo.[Get]().Execute()
End Sub
' 用户点击了 googleLogin 按钮。移动到 google Oauth url,以便用户可以登录到他们的 gogole 帐户
Public Sub GoogleLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GoogleLogin_Click.Click
End Sub
解决方案
推荐阅读
- postgresql - Npgsql.NpgsqlException(0x80004005):连接时出现异常:由于目标机器主动拒绝,无法建立连接
- google-calendar-api - 如何更新具有某些豁免的重复事件,但仍保持豁免实例的“已确认”状态?
- image - SwiftUI - 如何使来自不同大小的 URL 的图像适合框架?
- wpf - WPF:绑定到 ObservableCollection 中类的属性
- global-variables - 当“on_test_start”存在时,蝗虫任务方法无法获取全局值
- sql - 不使用 'INTERSECT' ,如何只检索两个表中存在的行?
- php - 在同一行的 PHP PDO 中不断给出 $_GET 错误
- string - 如何在 SwiftUI 中将字符串转换为整数?
- c++ - Qt中如何将非成员函数中的数据导入到成员函数中?
- jquery - 一次使用后的jQuery滚动删除功能