首页 > 解决方案 > 如何使用 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

标签: c#asp.net.netgoogle-oauthgoogle-signin

解决方案


推荐阅读