0

I am trying the below code but it always gave me the same exception...

using Google calender api v3

using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Calendar;

Google.GData.Calendar.CalendarService calendarService = new Google.GData.Calendar.CalendarService("App name");
        calendarService.setUserCredentials("username@gmail.com", "password");

        CalendarQuery query = new CalendarQuery();
        query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
        CalendarFeed resultFeed = (CalendarFeed)calendarService.Query(query);
        Console.WriteLine("Your calendars:\n");
        foreach (CalendarEntry entry in resultFeed.Entries)
        {
            Console.WriteLine(entry.Title.Text + "\n");
        }

help me!

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Gaurav Kaushik
  • 187
  • 1
  • 1
  • 12
  • Google calendar as far as I know doesn't allow client login you need to use Oauth2. also I recommend the newest client lib. https://www.nuget.org/packages/Google.Apis.Calendar.v3/ – Linda Lawton - DaImTo Dec 18 '14 at 10:51
  • DalmTo... thanks for the response i already updated my nuget dll still i am facing the same problem do i need to use Oauth2 or is there any other way for the same. – Gaurav Kaushik Dec 18 '14 at 10:57

1 Answers1

1

In order to access Google Calendar you need to be Authenticated with Oauth2, to my knowledge client login is not allowed with Google Calendar API v3.

Update: From the Google Calendar API documentation

About authorization protocols

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google+ Sign-In, some aspects of authorization are handled for you.

The following is a simple example on how to create an authenticated calendar service. The code was ripped from the Google Calendar api C# authentication tutorial

 string clientId = "";//From Google Developer console https://console.developers.google.com
 string clientSecret = "";//From Google Developer console https://console.developers.google.com
 string userName = ""//  A string used to identify a user.
 string[] scopes = new string[] {
    CalendarService.Scope.Calendar, // Manage your calendars
    CalendarService.Scope.CalendarReadonly // View your Calendars
 };

// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets {
        ClientId = clientId, ClientSecret = clientSecret
    }, scopes, userName, CancellationToken.None, new FileDataStore("Daimto.GoogleCalendar.Auth.Store")).Result;

// Create the service.
    CalendarService service = new CalendarService(new BaseClientService.Initializer() {
        HttpClientInitializer = credential,
        ApplicationName = "Calendar API Sample",
    });
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • This is what i can't do i need to follow the Google client login I am trying with Google.GData.Client.dll, Google.GData.Calendar as i hope it is possible with Google client Login may be i am wrong somewhere now i am referring http://www.fryan0911.com/2009/03/c-using-google-data-apis-on-your.html but no result found,I am able to do client login inwith GoogleContacts I am sure there must be something for calender too, Please help me in that context... :) – Gaurav Kaushik Dec 18 '14 at 11:31
  • that tutorial is from Sunday, March 29, 2009 and is no longer valid with the current version of the Google Calendar api. Google is shutting down all of the client login APIs. You will need to use Oauth2. – Linda Lawton - DaImTo Dec 18 '14 at 11:33
  • Thanks for the explanation now i will follow Oauth2 – Gaurav Kaushik Dec 18 '14 at 11:39
  • Anytime. The tutorial has a full project on Github if you want something to play with. – Linda Lawton - DaImTo Dec 18 '14 at 11:40