Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3694126
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:27:34+00:00 2026-05-19T04:27:34+00:00

I have been racking my brain for a few days trying to get a

  • 0

I have been racking my brain for a few days trying to get a list of calendars from Google using DotNetOpenAuth.

I can successfully get a list of contacts using the DotNetOpenAuth Samples. I have integrated it with my domain using the OpenId+OAuth. Everything works great to get a list of contacts.

So from there I modified the code to try to retrieve a list of Calendars and I keep getting a 401 Unauthorized error.

I know it is authorizing because I can get the contact list. Does anyone have a code example how they are retrieving calendars or calendar events using the DotNetOpenAuth with Google???

Thanks

Update:

Thanks for the response. I have read everything I can get my hands on. Here is what I have done so far

Step 1: I created a new GetCalendarEndPoint in the GoogleConsumer.cs

private static readonly MessageReceivingEndpoint GetCalendarEndpoint = new MessageReceivingEndpoint("https://www.google.com/calendar/feeds/default", HttpDeliveryMethods.GetRequest);

Step 2: Next I created a new method GetCalendars patterned after the GetContacts Method in GoogleConsumer.cs – (Rebuilt the dll etc.)

    public static XDocument GetCalendars(ConsumerBase consumer, string accessToken, int maxResults/* = 25*/, int startIndex/* = 1*/) {
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            var request = consumer.PrepareAuthorizedRequest(GetCalendarEndpoint, accessToken);
            var response = consumer.Channel.WebRequestHandler.GetResponse(request);
            string body = response.GetResponseReader().ReadToEnd();
            XDocument result = XDocument.Parse(body);
            return result;

Step 3: In my Application I modified the ScopeURI to the the Calendar URI from GoogleConsumer as follows

private IAuthenticationRequest GetGoogleRequest()
{
    Realm realm = Request.Url.Scheme + Uri.SchemeDelimiter + Global.GoogleTokenManager.ConsumerKey + "/";
    IAuthenticationRequest authReq = relyingParty.CreateRequest(GoogleOPIdentifier, realm);

    // Prepare the OAuth extension
    string scope = GoogleConsumer.GetScopeUri(GoogleConsumer.Applications.Calendar);
    Global.GoogleWebConsumer.AttachAuthorizationRequest(authReq, scope);

    // We also want the user's email address
    var fetch = new FetchRequest();
    fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
    authReq.AddExtension(fetch);

    return authReq;
}

However, when I run the app I get 401 Unauthorized when I make the following call

 var calendars = GoogleConsumer.GetCalendars(Global.GoogleWebConsumer, State.GoogleAccessToken, 25, 1);

I have also checked that the State.GoogleAccess token exists by simply displaying it on my screen before I trigger the method that makes this call.

Again, if I exectute

var calendars = GoogleConsumer.GetContacs(Global.GoogleWebConsumer, State.GoogleAccessToken, 25, 1);

then it works??????? Thanks for you help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:27:34+00:00Added an answer on May 19, 2026 at 4:27 am

    I’ve been suffering through exactly the same thing for most of the weekend.

    I think that after much fiddling with Fiddler I’ve found the cause and have a solution which, although not pretty, seems to work. I found that I was able to access the calendar feed by copying and pasting the DNOA-generated Uri into a browser, but always got a 401 when attempting programmatic access. This is apparently because the default auto-redirect behavior of HttpWebRequest discards any cookies that the redirect is attempting to set. The Contacts feed doesn’t set any cookies during the redirect, so it is immune.

    The first time you request a calendar feed (even with a properly constructed and signed OAuth request), Google replies with a redirect containing a cookie. If you don’t present that “calendar cookie” at the same time as your feed request you will get a 401 Unauthorized when you attempt to follow the redirect to the feed.

    here’s the cookie-setting header from Google:

    HTTP/1.1 302 Moved Temporarily
    Set-Cookie: S=calendar=y7AlfgbmcqYl0ugrF-Zt9A;Expires=Tue, 10-Jan-2012 03:54:20 GMT;Secure
    

    Here’s what I’m doing to make it work:

    // wc: WebConsumer
    var calRequest = wc.PrepareAuthorizedRequest(erp2, authTokenRsp.AccessToken);
    // need to stop redirect to capture calendar cookie token:
    calRequest.AllowAutoRedirect = false;
    var calResponse = calRequest.GetResponse();
    var redirectCookie = calResponse.Headers[System.Net.HttpResponseHeader.SetCookie];
    
    var cookiedCalRequest = wc.PrepareAuthorizedRequest(erp2, authTokenRsp.AccessToken);
    cookiedCalRequest.Headers[System.Net.HttpRequestHeader.Cookie] = redirectCookie;
    var calFeedResponse = cookiedCalRequest.GetResponse();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Stack Overflowers: I have been racking my brain trying to get an List(of T)
so i have been racking my brain with trying to get an audio/video broadcasting
Okay I have been racking my brain trying to build a JSON array from
I've been racking my brain trying to get my softphone to dial numbers on
I've been racking my brain over this for the past few days and I'm
I have been racking my brain and searching google for almost the whole day
In trying to parse a date, I have been racking my brain for hours:
I've been running into an EXC_BAD_ACCESS bug and have been racking my brain trying
I have been racking my small brain for ages now, so can this be
Have been struggling with Javascript closure for a while trying to wrap brain around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.