lukejagodzinski / meteor-google-oauth-jwt

Implementation of Google OAuth 2.0 for server-to-server interactions
MIT License
9 stars 4 forks source link

POST request Google Calendar results in "Parse Error" #7

Open sanneterpstra opened 8 years ago

sanneterpstra commented 8 years ago

I'm trying to integrate Google Calendar in my meteor app. Reading events goes fine but when I try to create an event by using the post request I'm getting a Parse Error.

This is the code for the request (using Google's example code):

    var result = HTTPJWT.post("https://www.googleapis.com/calendar/v3/calendars/{My calendar id}/events", {
        headers: {
            'Content-Type': 'application/json ; charset=UTF-8"'
        },
        params: {
            'summary': 'Google I/O 2015',
            'location': '800 Howard St., San Francisco, CA 94103',
            'description': 'A chance to hear more about Google\'s developer products.',
            'start': {
                'dateTime': '2015-05-28T09:00:00-07:00',
                'timeZone': 'America/Los_Angeles'
            },
            'end': {
                'dateTime': '2015-05-28T17:00:00-07:00',
                'timeZone': 'America/Los_Angeles'
            }
        }
    });

However the response I'm getting back is an Parse Error with no additional information. Error: failed [400] { "error": { "errors": [ { "domain": "global", "reason": "parseError", "message": "Parse Error" } ], "code": 400, "message": "Parse Error" } }

lukejagodzinski commented 8 years ago

It's the response from the server so it's not a problem with the package, so you shouldn't ask it here. Have you tried inserting only the summary?

sanneterpstra commented 8 years ago

Thanks for the quick response!

When I only insert the summary it still responds with a parseError. I tried using your suggested code in this issue:

var result = HTTPJWT.post('https://www.googleapis.com/calendar/v3/calendars/{YOUR_CALENDAR_ID}/events', {
    params: {
        'summary': 'Google I/O 2015'
    }
});

But then I get the following error:

Error: failed [400] {  "error": {   "errors": [    {     "domain": "global",     "reason": "parseError",     "message": "This API does not support parsing form-encoded input."    }   ],   "code": 400,   "message": "This API does not support parsing form-encoded input."  } } 

I'm not sure what to do.. Could you please help me with this?

lukejagodzinski commented 8 years ago

Have you tried without setting headers? It's hard to tell what is the reason.

sanneterpstra commented 8 years ago

Yes I also tried without headers but then the API says it doesn't support form-encoded input. When setting the headers to JSON, the form-encoded parse error goes away but then it just gives a parse error. And when using a JSON header without any params it says it needs an end date.

So it seems that the API only accepts JSON formatted data but when I give it JSON data by putting it in the params it returns a parse error without any further information.

lukejagodzinski commented 8 years ago

You know, it's hard to predict what is the source of the error. I've created this package to access Google Endpoint API. It's based on the node.js package. It worked well in my project. I haven't tested it with Calendar API. However as you said it work on getting values but you can't insert. What I would suggest is checking in Google Chrome Developer Tools what requests are send when using this package and what requests are send using the Google Sandbox. Thanks to that you may compare the data and see a difference.

shamoon1992 commented 8 years ago

invalidRequest (HTTP status 400): Your request was not a valid request.

lukejagodzinski commented 8 years ago

@shamoon1992 and? :)

MVakas commented 8 years ago

Hi have you resolved this? I’m having the same issue.

vasiledoe commented 6 years ago

same fucking error!!!!!

osman-masood commented 6 years ago

I'm also getting this error response from Google when trying to create a calendar event.

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

I'm only setting a start.dateTime and end.dateTime and nothing else (though I've also tried setting a summary and description, but get the same thing).

POST https://www.googleapis.com/calendar/v3/calendars/primary/events?access_token=my_valid_access_token
Accept: application/json
{"start":{"dateTime":"2018-07-02T13:41:55Z"},"end":{"dateTime":"2018-07-02T13:56:55Z"}}

EDIT

I found the solution. It was that I was simply missing the Content-Type header. I guess it would've been nice if it told me that. Either way, yay!

mehtakovid commented 4 years ago

Even after adding contentType("application/json\r\n") still seeing the same error. Tried hitting it on google API explorer works like charm but with rest assured it just gives the same error again. Has anyone found any other solution to the issue ?

rsulca8 commented 3 years ago

I'm also getting this error response from Google when trying to create a calendar event.

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

I'm only setting a start.dateTime and end.dateTime and nothing else (though I've also tried setting a summary and description, but get the same thing).

POST https://www.googleapis.com/calendar/v3/calendars/primary/events?access_token=my_valid_access_token
Accept: application/json
{"start":{"dateTime":"2018-07-02T13:41:55Z"},"end":{"dateTime":"2018-07-02T13:56:55Z"}}

EDIT

I found the solution. It was that I was simply missing the Content-Type header. I guess it would've been nice if it told me that. Either way, yay!

Thanks! that was. I had " ContentType