1

I'm running into a bit of an issue with the Google Calendar API. I'm trying to create an even on a calendar, but I'm getting stuck at querying the calendar service. I'm using this guide I found on codeproject (Guide), and it links you to this authentication guide (Authentication Guide). I was able to make it through step 5 under "OAuth 2.0 flows" on the Authentication guide, and got the access token, and refresh token, but when I attempt to query the calendar service, I get this error:

"Execution of request failed: https://www.google.com/calendar/feeds/default/allcalendars/full", "The remote server returned an error: (401) Unauthorized."

I'm not sure what I'm doing wrong, I authorized the user and have the access token. So I would think I'm missing something small, but I have been banging my head for the past day trying to figure it out.

This is the code I'm using:

        Google.GData.Client.GAuthSubRequestFactory authFactory = new Google.GData.Client.GAuthSubRequestFactory("cl", "API Project");
        authFactory.Token = "ya29...";
        authFactory.KeepAlive = true;
        Google.GData.Calendar.CalendarService service = new CalendarService("API Project");
        service.RequestFactory = authFactory;
        Uri postUri = new Uri(AllCalendarFeed);
        Google.GData.Calendar.CalendarQuery CalendarQuery = new Google.GData.Calendar.CalendarQuery();
        CalendarQuery.Uri = postUri;

        //Errors out on this line:
        Google.GData.Calendar.CalendarFeed calFeed = service.Query(CalendarQuery);

        string CalendarID = "";
        if (calFeed != null && calFeed.Entries.Count > 0)
        {
            foreach (CalendarEntry CalEntry in calFeed.Entries)
            {
                //Commented to post the new appointments 
                //on the main calendar instead of cleverfox calendar
                //if (CalEntry.Title.Text.Contains("Cleverfox") == true)
                //{
                //CalendarID = CalEntry.Title.Text;
                CalendarID = CalEntry.EditUri.ToString().Substring(CalEntry.EditUri.ToString().LastIndexOf("/") + 1);
                break;
                //}
            }
        }

Any help is greatly appreciated. Thank you.

juniperi
  • 3,723
  • 1
  • 23
  • 30
Vandel212
  • 1,074
  • 1
  • 13
  • 28
  • I assume the actual code has the full token where you put `authFactory.Token = "ya29...";`? Otherwise, that seems way too short to be valid. Also, are you sure you don't have them backwards? – Bobson Jul 16 '13 at 23:32
  • You assume right. I just don't know how sensitive that information is. I'm pretty sure I have it right. – Vandel212 Jul 17 '13 at 00:34

0 Answers0