Gmail api mvc 5未获得授权IIS

Gmail api mvc 5未获得授权IIS,api,model-view-controller,gmail,Api,Model View Controller,Gmail,我在MVC5项目中使用gmail api,它在本地(调试模式)上运行良好 这是我的代码: UserCredential-credential1; var folder=System.Web.HttpContext.Current.Server.MapPath(“/App_Data/MyGoogleStorage”); credential1=等待GoogleWebAuthorizationBroker.AuthorizationAsync( 新客户的秘密 { ClientId=“xxxxxxxx

我在MVC5项目中使用gmail api,它在本地(调试模式)上运行良好

这是我的代码:

UserCredential-credential1;
var folder=System.Web.HttpContext.Current.Server.MapPath(“/App_Data/MyGoogleStorage”);
credential1=等待GoogleWebAuthorizationBroker.AuthorizationAsync(
新客户的秘密
{
ClientId=“xxxxxxxxxxx.apps.googleusercontent.com”,
ClientSecret=“xxxxxxxxxxxxxxxx”
},
//GoogleClientSecrets.Load(stream.Secrets),
//此OAuth 2.0访问范围允许以只读方式访问经过身份验证的应用程序
//用户的帐户,但不是其他类型的帐户访问。
新[]{GmailService.Scope.GmailReadonly,GmailService.Scope.MailGoogleCom,GmailService.Scope.GmailModify},
“用户”,
取消令牌。无,
新文件数据存储(文件夹)
);

但是当我发布它并尝试从iis运行时,我得到了:

[System.AggregateException:发生了一个或多个错误。-->System.Net.HttpListener异常:在System.Net.HttpListener.AddAllPrefixes()在System.Net.HttpListener.Start()在Google.API.Auth.OAuth2.LocalServerCodeReceiver.StartListener()在Google.API.Auth.OAuth2.LocalServerCodeReceiver.d_u8.MoveNext()上拒绝访问---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)在Google.API.Auth.OAuth2.AuthorizationCodeInstalledApp.d_u8.MoveNext()上从引发异常的上一个位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)在Google.API.Auth.OAuth2.GoogleWebAuthorizationBroker.d_u4.MoveNext()上从引发异常的上一个位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)在Google.API.Auth.OAuth2.GoogleWebAuthorizationBroker.d_u1.MoveNext()上引发异常的上一个位置的堆栈结束跟踪---内部异常堆栈跟踪的结束---C:\Users\Administrator\Desktop\DataOtomasyon\DataOtomasyon\Helpers\gmailApi.d_u2.MoveNext()中的System.Threading.Tasks.Task`1.GetResultCore(布尔waitCompletionNotification)位于Dataomasyon.Helpers.gmailApi.cs:第58行--->(内部异常#0)System.Net.HttpListenerException(0x80004005):在Google.API.Auth.OAuth2.LocalServerCodeReceiver.StartListener()的Google.API.Auth.OAuth2.LocalServerCodeReceiver.StartListener()的System.Net.HttpListener.AddAllPrefixes()的系统.Net.HttpListener.Start()的访问被拒绝---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)在Google.API.Auth.OAuth2.AuthorizationCodeInstalledApp.d_u8.MoveNext()上从引发异常的上一个位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)在Google.API.Auth.OAuth2.GoogleWebAuthorizationBroker.d_u4.MoveNext()上从引发异常的上一个位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)在Google.API.Auth.OAuth2.GoogleWebAuthorizationBroker.d_u1.MoveNext()上引发异常的上一个位置的堆栈结束跟踪
这可能是很久以前提出的问题,但我遇到了相同的问题,解决方法是使用什么,而不是不设置代码接收器参数。结果表明,在未定义代码接收器时,默认情况下使用LocalServerCodeReceiver。

400。这是一个错误。错误:重定向\u uri \u与请求中的重定向uri不匹配,urn:ietf:wg:oauth:2.0:oob,只能由本机应用程序的客户端ID使用。WEB客户端类型不允许使用它。您可以在了解更多请求详细信息时为本机应用程序创建客户端ID,这是我们所知的全部。如果您当前在创建的凭据中使用WEB应用程序作为应用程序类型,则可以尝试在使用类型Other更新您的ClientId和ClientSecret值。
 credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true),
                new PromptCodeReceiver()).Result;