GoogleWebAuthorizationBroker.AuthorizeAsync()
登臺失敗(養殖4.5 NET)登臺服務器,但在本地服務器上效果很好。我已經遵循幫助熱線上的每個代碼仍然無濟於事。GoogleWebAuthorizationBroker.AuthorizeAsync登臺服務器失敗
這裏是我的代碼:
String gpath = Server.MapPath("credentials/siteAPI.json");
UserCredential credential;
string credPath = Server.MapPath("credentials");
using (var stream = new FileStream(gpath, FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { CalendarService.Scope.Calendar },//
"[email protected]",
CancellationToken.None,
new AppDataFileStore(credPath)
).Result;
}
而且我得到這個錯誤:
System.AggregateException: One or more errors occurred.
---> System.ComponentModel.Win32Exception: Access is denied
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() in C:\Users\mdril\Documents\GitHub\google-api-dotnet-client\Src\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 59
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at z2.Page_Load(Object sender, EventArgs e) in e:\hostingspaces\cal1234\mysitecalendar.com\wwwroot\z2.aspx.cs:line 169
---> (Inner Exception #0) System.ComponentModel.Win32Exception (0x80004005): Access is denied
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.d__1.MoveNext() in C:\Users\mdril\Documents\GitHub\google-api-dotnet-client\Src\GoogleApis.Auth.DotNet4\OAuth2\GoogleWebAuthorizationBroker.cs:line 59<---
根據其他筆記我看,這是由於在服務器端的權限問題,但有養殖網站,我沒有更多的權限控制。
有趣的是,當我從我的本地服務器複製其中一個批准的憑據到臨時服務器,然後一切正常!看起來,登臺服務器不能夠(或沒有權限)啓動屏幕來要求用戶進行令牌批准!
我該如何解決這個問題?
是gpath從Google開發者處下載的文件嗎?如果是這樣,你是否直接將文件複製到你的項目中? – apramc
如果您有,請確保您將生成行動更改爲「內容」和複製到輸出目錄到「複製總是」 – apramc
是gpath是我從谷歌開發者控制檯下載的憑據,是的我複製到我的項目本地並上傳到我的登臺服務器也是如此。 –