Error: redirect_uri_mismatch In Google Login in MVC Application

Error: redirect_uri_mismatch In Google Login in MVC Application

我正在尝试通过 MVC C# 应用程序将视频上​​传到 YouTube。我正在关注这个 link

每当我尝试 运行 应用程序时,我都会收到来自 Google.

的错误消息

错误:redirect_uri_mismatch

请求中的重定向 URI,http://localhost:52271/authorize/, does not match the ones authorised for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/CCC-XXX.apps.googleusercontent.com?project=XXXX 更新授权的重定向 URI。

这是我的 Json 文件。

这是我的 Google 控制台应用程序:

错误:

有什么问题吗?

谢谢。

您需要在 Google API Console 中添加 localhost 到您的授权域名。

您在 Google 开发者控制台中设置的重定向 URI 必须与您发送请求的位置完全匹配。如果您注意到端口号正在更改。这是因为visual studio有使用visual stuido调试的习惯,会随机添加端口号

为使用 IIS Express 的 Web 应用程序项目指定端口

  1. 在解决方案资源管理器中,右键单击项目,然后单击 select 属性。单击 Web 选项卡。
  2. 在服务器部分的使用本地 IIS Web 服务器下,在项目 URL 框中更改端口号。
  3. 在“项目 URL”框的右侧,单击“创建虚拟目录”,然后单击“确定”。
  4. 在“文件”菜单中,单击“保存所选项目”。
  5. 要验证更改,请按 CTRL+F5 到 运行 项目。新的端口号出现在浏览器的地址栏中。

How to: Specify a Port for the ASP.NET Development Server

来自位于 https://developers.google.com/identity/protocols/OAuth2UserAgent?hl=en_US#example 的 Google 文档 REDIRECT_URI 应该与正在提供页面的 URL 相同。 我终于看到了这个,把 URL 放在我调用 Google 身份验证的页面上,它就像一个魅力。