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

  • Home
  • SEARCH
  • 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 9123027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:14:27+00:00 2026-06-17T06:14:27+00:00

I’m trying to create a Calendar through the Google API as per the documentation

  • 0

I’m trying to create a Calendar through the Google API as per the documentation. I am trying to avoid using the Client libraries and do all communication with the API through custom webrequests and so far that has been working nicely but on this particular one I’m struggling with a “parse error”.

Please do not refer to solutions that use the client libraries (service.calendars().insert(…)).

This is a dumbed down version of my code (still not working):

var url = string.Format
(
    "https://www.googleapis.com/calendar/v3/calendars?key={0}",
    application.Key
);

var httpWebRequest = HttpWebRequest.Create(url) as HttpWebRequest;
httpWebRequest.Headers["Authorization"] = 
    string.Format("Bearer {0}", user.AccessToken.Token);                    
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/json";
httpWebRequest.CookieContainer = new CookieContainer();

// Obviously the real code will serialize an object in our system.
// I'm using a dummy request for now,
// just to make sure that the problem is not the serialization.
var requestText =
      "{" + Environment.NewLine
    + "\"summary\": \"test123\"" + Environment.NewLine
    + "}" + Environment.NewLine
    ;

using (var stream = httpWebRequest.GetRequestStream())
using (var streamWriter = new System.IO.StreamWriter(stream))
{
    streamWriter.Write(System.Text.Encoding.UTF8.GetBytes(requestText));
}

// GetSafeResponse() is just an extension that catches the WebException (if any)
// and returns the WebException.Response instead of crashing the program.
var httpWebResponse = httpWebRequest.GetSafeResponse();

As you can see, I’ve given up on sending serialized objects for now and I’m just trying to get it working with a very simple dummy request:

{
"summary": "test123"
}

Yet the response is still just:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "parseError",
    "message": "Parse Error"
   }
  ],
  "code": 400,
  "message": "Parse Error"
 }
}

The accessToken is valid and not expired, the application key is correct.

What am I doing wrong or missing?

Thanks in advance,

  • 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-06-17T06:14:28+00:00Added an answer on June 17, 2026 at 6:14 am

    I figured it out and got it working!

    While David’s suggestions weren’t the solution by themselves, he put me on the right track by telling me to use a packet sniffer (I ended up using Wireshark but that’s not really the point).

    As it turns out, there were two errors in my dumbed down code. One so glaringly obvious that it makes me blush, one slightly more devious.

    First of all,

    using (var streamWriter = new StreamWriter(stream))
    {
        streamWriter.Write(Encoding.UTF8.GetBytes(requestText));
    }
    

    should of course be

    using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
    {
        streamWriter.Write(requestText);
    }
    

    as streamWriter.Write does a ToString() on the parameter and Byte[].ToString() just returns “System.Byte[]”. Embarassing!

    Secondly, the default UTF8 encoding adds the byte order mark \357\273\277, which also renders the content invalid as far as google is concerned. I found how to fix this problem here on stackoverflow.

    So for anyone struggling with this, here is the final solution.

    var url = string.Format
    (
        "https://www.googleapis.com/calendar/v3/calendars?key={0}",
        application.Key
    );
    
    var httpWebRequest = HttpWebRequest.Create(url) as HttpWebRequest;
    httpWebRequest.Headers["Authorization"] = 
        string.Format("Bearer {0}", user.AccessToken.Token);                    
    httpWebRequest.Method = "POST";
    // added the character set to the content-type as per David's suggestion
    httpWebRequest.ContentType = "application/json; charset=UTF-8";
    httpWebRequest.CookieContainer = new CookieContainer();
    
    // replaced Environment.Newline by CRLF as per David's suggestion
    var requestText = string.Join
    (
        "\r\n",
        "{",
        " \"summary\": \"Test Calendar 123\"",
        "}"
    );
    
    using (var stream = httpWebRequest.GetRequestStream())
    // replaced Encoding.UTF8 by new UTF8Encoding(false) to avoid the byte order mark
    using (var streamWriter = new StreamWriter(stream, new UTF8Encoding(false)))
    {
        streamWriter.Write(requestText);
    }
    

    Hope this helps someone!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.