我已经将我的asp.net应用程序从谷歌日历V2迁移到V3 Beta,但现在他们已经发布了新版本的1.8.1.820版本的DLL,所以任何人都可以在这方面帮助我如何转换。在我的V3测试版中,我使用下面的代码
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 :(得分:0)
首先,日历API不是测试版,它可以在此处使用 - 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 sample或ASP.NET MVC code snippet