重定向_URI_missmatch:使用c#在Google Plus API上验证时出错?
我遵循下面的示例,使用以下代码对Google plus API进行身份验证:重定向_URI_missmatch:使用c#在Google Plus API上验证时出错?,c#,asp.net-mvc-4,google-api,google-plus,google-api-dotnet-client,C#,Asp.net Mvc 4,Google Api,Google Plus,Google Api Dotnet Client,我遵循下面的示例,使用以下代码对Google plus API进行身份验证: string[] scopes = new string[] {PlusService.Scope.PlusLogin, PlusService.Scope.UserinfoEmail, PlusService.Scope.UserinfoProfile }; // here is where we Request the user
string[] scopes = new string[] {PlusService.Scope.PlusLogin,
PlusService.Scope.UserinfoEmail,
PlusService.Scope.UserinfoProfile
};
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
UserCredential credential =
GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
ClientId = "xxxx-jh7244ds8ruseviasg0a5g6ln09p0l44.apps.googleusercontent.com",
ClientSecret = "e5kjgbVJz8o92Xqb7RvpzqPk"
},
scopes,
Environment.UserName,
CancellationToken.None,
new FileDataStore("Daimto.GooglePlus.Auth.Store")
).Result;
运行代码时,出现以下错误:
即使是在上运行的程序,以下是我在谷歌开发者控制台中的设置
在visual studio中运行代码时,除非您告诉visual studio不要这样做,否则visual studio将在每次运行时添加随机端口号 您从中发送的重定向URI必须与您在Google开发者控制台中输入的URI完全匹配 您当前正在从运行
http://localhost:53732/authorize
您在开发人员控制台中设置的唯一重定向uri是
http://lostlhost:53308/sign-in
修复Visual studio,使其停止添加随机端口,然后将该端口添加到开发人员控制台页面
问题二:
您正在使用的代码用于已安装的应用程序,而不是web应用程序。它将在您的本地计算机上正常工作,因为您可以打开web浏览器。但是,当您将其部署到Web服务器时,它将不起作用。你将不得不使用更像这样的东西
当您在VisualStuido中运行代码时,除非您告诉它不要运行,否则VisualStudio将在每次运行时添加随机端口号 您从中发送的重定向URI必须与您在Google开发者控制台中输入的URI完全匹配 您当前正在从运行
http://localhost:53732/authorize
您在开发人员控制台中设置的唯一重定向uri是
http://lostlhost:53308/sign-in
修复Visual studio,使其停止添加随机端口,然后将该端口添加到开发人员控制台页面
问题二:
您正在使用的代码用于已安装的应用程序,而不是web应用程序。它将在您的本地计算机上正常工作,因为您可以打开web浏览器。但是,当您将其部署到Web服务器时,它将不起作用。你将不得不使用更像这样的东西
尝试在您的项目上启用SSL(Web project->Properties->SSL Enabled=true),然后将这些URL用于您的google凭据。出现相同的错误似乎表明您正在重定向到控制台上未授权的URL。尝试在您的项目上启用SSL(Web project->Properties->SSL Enabled=true),然后将这些URL用于您的google凭据。出现的错误似乎与您收到的错误相同,表明您正在重定向到未经控制台授权的URL。请记住,您是在重定向uri而非JS源之后。请记住,您是在重定向uri而非JS源之后。