google-api - redirect_uri_mismatch 请求中的重定向 URI 与 OAuth 客户端授权的不匹配

标签 google-api youtube-api google-oauth youtube-data-api

我有以下客户 secret

{
  "web": {
    "client_id": "testid",
    "project_id": "testproj",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://www.googleapis.com/oauth2/v3/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "test-sec",
    "redirect_uris": [
      "https://localhost:8080/oauth2callback"
    ]
  }
}

我得到

"Error: redirect_uri_mismatch The redirect URI in the request, http://127.0.0.1:8414/authorize/, does not match the ones authorized for the OAuth client.



要更新授权的重定向 URI,请访问:"。您能否提出建议,如何修复它。

我正在使用 C#。我已经用这个创建了凭据 -
GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, scopes,
                                             "user",
                                              CancellationToken.None, 
                                              new FileDataStore(Directory.GetCurrentDirectory() + "\\AccessToken\\" , 
                                             true)).Result; 

但是第一次,它弹出登录,一旦我登录,它就在文件夹中创建了 Google.Apis.Auth.OAuth2.Responses.TokenResponse-user 文件。有没有办法绕过第一次登录?

谢谢。

最佳答案

https://console.developers.google.com 中创建凭据时:

Credentials

通过选择 Create credentials 来点击 OAuth client ID 后:

Create credentials

选择其他作为应用程序类型:

.

您应该拥有以下格式的凭据:

{
  "installed": {
    "client_id": "...",
    "project_id": "...",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "...",
    "redirect_uris": [
      "urn:ietf:wg:oauth:2.0:oob",
      "http://localhost"
    ]
  }
}

现在,您的 OAuth2 链接应该可以在 redirection_uri 参数中的任何端口作为 http://localhost:8414 使用(例如,8414 作为随机端口)。而你不再是这个错误:

Error: redirect_uri_mismatch The redirect URI in the request, http://localhost:8414/authorize/, does not match the ones authorized for the OAuth client.

关于google-api - redirect_uri_mismatch 请求中的重定向 URI 与 OAuth 客户端授权的不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53680886/

相关文章:

oauth-2.0 - 永远 "Have Offline Access"| Google OAuth 2

rest - 通过 REST v3 上传的文件显示为 "Untitled"

php - 未发送 Google YouTube API 刷新 token

iframe - Youtube Iframe 禁用暂停视频

youtube-api - 在没有视频 ID 的情况下初始化 YouTube iframe 播放器

php - 当每个可能的 URI 都在控制台中时,Google OAuth2 PHP 客户端redirect_uri_mismatch

node.js - Google oauth 不返回电子邮件 Passport 身份验证

javascript - gapi.auth javascript 命令未正确执行

reactjs - OnSelect 不适用于 react-Google-places-autocomplete

javascript - 谁能帮我让搜索栏正常工作,因为我现在有 JS 提示符?