I'm trying to read my own Google calendar with the v3 API (http://code.google.com/p/google-api-dotnet-client/). What I eventually want is to display my own calendar from Google Calendar on my site through a custom control (and later on let people make custom appointments). Every sample I'm reading is based on the premise that I should manually give access to my data. Still in the Google API console I created an application with a API key. I’m trying to create a valid IAuthentication for my code. Never the less I don’t get which authentication I have to use. Below is a miserable attempt, who can help me with this?
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);
}