1
我正在尝试使用v3 API(http://code.google.com/p/google-api-dotnet-client/)阅读我自己的Google日历。我最终想要的是通过自定义控件在我的网站上显示来自Google日历的自己的日历(之后让人们进行自定义约会)。我正在阅读的每个示例都基于我应该手动提供对数据的访问权的前提。仍然在Google API控制台中,我使用API密钥创建了一个应用程序。我正在尝试为我的代码创建一个有效的IAuthentication。从来没有,我不知道我必须使用哪种身份验证。下面是一个悲惨的尝试,谁可以帮助我呢?用于dotnet的Google API v3;通过API密钥使用日历
public void TestMethod1()
{
// http://code.google.com/p/google-api-dotnet-client/wiki/OAuth2
NativeApplicationClient provider = NativeApplicationClient(GoogleAuthenticationServer.Description);
NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "x";
provider.ClientSecret = "x";
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
Google.Apis.Calendar.v3.CalendarService service = new Google.Apis.Calendar.v3.CalendarService(auth);
var result = service.Events.List("primary").Fetch();
Assert.IsTrue(result.Items.Count > 0);
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
return arg.ProcessUserAuthorization("", state);
}