1

我已將我的asp.net應用程序從Google日曆V2遷移到V3測試版,但現在他們已經發布了新版本1.8.1.820的新DLL,請問任何人都可以在這方面幫助我,我該如何轉換。在我的V3 beta版本我是用下面的代碼從Google日曆v3測試版遷移到v3 1.8.1.820

private CalendarService CreateService(string token) 
{ 
    KeyValuePair<string, string> credentials = Common.Get3LOCredentials(); 
    var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); 
    provider.ClientIdentifier = credentials.Key; 
    provider.ClientSecret = credentials.Value; 
    var auth = new Google.Apis.Authentication.OAuth2.OAuth2Authenticator<NativeApplicationClient>(provider, (p) => GetAuthorization(provider, token, credentials.Key, credentials.Value)); 
    CalendarService service = new CalendarService(new BaseClientService.Initializer() 
    { 
     Authenticator = auth, 
     ApiKey = ConfigurationManager.AppSettings["APIkey"].ToString(), 
     GZipEnabled = false 
    }); 
    provider = null; 
    return service; 
} 

正如有新的版本,他們沒有NativeApplicationClient類等多種功能,他們沒有。因此,如果任何人有,請給我提供一些文檔,因爲Google沒有爲ASP.NET開發人員提供良好的文檔。

這是我使用谷歌日曆的新版本的代碼: -

private CalendarService CreateService(string token) 
{ 
    GoogleAuthorizationCodeFlow flow = null; 
    var assembly = Assembly.GetExecutingAssembly();  
    KeyValuePair<string, string> credentials = Common.Get3LOCredentials(); 
    UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = credentials.Key, ClientSecret = credentials.Value }, new[] { "https://www.googleapis.com/auth/calendar" }, "user", CancellationToken.None, new FileDataStore("Calendar.Sample.Store")).Result; 
    var service = new CalendarService(new BaseClientService.Initializer() 
    { 
     HttpClientInitializer = credential, 
     ApplicationName = "Calendar API Sample", 
    }); 
    return service; 
} 
+0

難道你不喜歡每個版本如何從最後一個重大突破變化。去Google! – Craig

回答

0

首先日曆API是不是beta,這是可以在這裏 - https://www.nuget.org/packages/Google.Apis.Calendar.v3/

該庫在過去的幾個月裏處於測試階段,我們努力提高質量並消除DotNetOpenAuth中的依賴。看看公告博客 - http://google-api-dotnet-client.blogspot.com/,所有更改都在那裏解釋。

從版本1.8.1開始,我們不會有任何不兼容的更改,因爲庫已達到GA(通用可用性)。所有OAuth 2.0文檔均可在https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth獲得。看看這個頁面,並告訴我們是否有任何遺漏。具體來說,你可以看看ASP.NET sampleASP.NET MVC code snippet

+0

感謝您的回覆。我已經嘗試過這部分,但我得到異常「一個或多個異常」請檢查我已經更新它的問題,在上面的代碼中,我將CalendarService.Scope.Calendar作爲null,我不知道爲什麼我將它作爲null我需要在第一次身份驗證時指定我們獲得的accessToken,因爲我沒有看到任何我們在哪裏指定令牌 –

+0

我認爲Google開發人員提到的代碼是針對已安裝的應用程序的,但我正在集成到web應用程序中需要在每個請求中指定AccessToken,那麼我可以在哪裏使用API​​在請求中指定AccessToken。我研究過它,但只得到舊代碼。 –