IM和正常工作的地方(調試模式)Gmail的API MVC 5沒有得到我的MVC 5項目使用Gmail API授權IIS
繼承人我的代碼:
UserCredential credential1; var folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage"); credential1 = await GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecrets { ClientId = "xxxxxxxxxxxx.apps.googleusercontent.com", ClientSecret = "xxxxxxxxxxxxxxxxxxx" }, //GoogleClientSecrets.Load(stream).Secrets, // This OAuth 2.0 access scope allows for read-only access to the authenticated // user's account, but not other types of account access. new[] { GmailService.Scope.GmailReadonly, GmailService.Scope.MailGoogleCom, GmailService.Scope.GmailModify }, "user", CancellationToken.None, new FileDataStore(folder) );
但是當我發佈並嘗試從IIS中運行我得到:
[ System.AggregateException: One or more errors occurred. ---> System.Net.HttpListenerException: Access is denied at System.Net.HttpListener.AddAllPrefixes() at System.Net.HttpListener.Start() at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.StartListener() at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at DataOtomasyon.Helpers.gmailApi.d__2.MoveNext() in C:\Users\Administrator\Desktop\DataOtomasyon\DataOtomasyon\Helpers\gmailApi.cs:line 58 ---> (Inner Exception #0) System.Net.HttpListenerException (0x80004005): Access is denied at System.Net.HttpListener.AddAllPrefixes() at System.Net.HttpListener.Start() at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.StartListener() at Google.Apis.Auth.OAuth2.LocalServerCodeReceiver.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.AuthorizationCodeInstalledApp.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext()<--- ]
我檢查權限所有可用的IIS用戶並授予讀/寫權限對所有這些我真的很困惑,任何幫助,將不勝感激
400.這是一個錯誤。 錯誤:redirect_uri_mismatch 請求中的重定向URI urn:ietf:wg:oauth:2.0:oob只能由本機應用程序的客戶端ID使用。它不適用於WEB客戶端類型。您可以在https://console.developers.google.com/apis/credentials/oauthclient創建本地應用的客戶端ID 瞭解更多 請求細節 這就是我們所知道的。 – harun
如果您目前在創建的憑證中使用_Web Application_作爲Application類型,則可以嘗試使用** Other **類型創建一個新的憑證,並相應地更新您的ClientId和ClientSecret值。 –