KoalaTea / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

Error 400 (Bad Request) while inserting events to Calendar #86

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi
I'm developing a Python desktop application that will interact with Google 
Calendar using v3 API and OAth2
I'm using "google-api-python-client-1.0beta7"

The problem is that I get "HttpError 400 Bad Request" for some methods, while 
some other methods work fine.

For example I get Bad Request for this method:

request = service.events().insert(
    body=gevent,
    calendarId=remoteGroupId,
    sendNotifications=False,
)

My request details.

uri=u'https://www.googleapis.com/calendar/v3/calendars/93mfmsvanup0tllng6tgpm1g8
8@group.calendar.google.com/events?alt=json&key=AI39si4QJ0bmdZJd7nVz0j3zuo1JYS3W
UJX8y0f2mvGteDtiKY8TUSzTsY4oAcGlYAM0LmOxHmWWyFLU'
method=u'POST'
headers={'content-type': 'application/json', 'accept-encoding': 'gzip, 
deflate', 'accept': 'application/json', 'user-agent': 
'google-api-python-client/1.0'}
body='{"kind": "calendar#event", "end": {"timeZone": "GMT", "dateTime": 
"20120123T120839"}, "description": "", "summary": "task1", "start": 
{"timeZone": "GMT", "dateTime": "20120123T110839"}, "calendarId": 
"93mfmsvanup0tllng6tgpm1g88@group.calendar.google.com", "id": 
"starcal#task#EA#O1iqEg"}'

Ans also this method gives 400:
service.colors().get().execute()

But some other requests works, for example.
service.calendarList().list().execute()

I have searched the web, some other guys having this problem have found "System 
Date" or "Request without Headers" the problem. But I checked both, my system 
date is ok, and also headers seems to be ok (as I pasted above)

Original issue reported on code.google.com by saeed....@gmail.com on 23 Jan 2012 at 10:56

GoogleCodeExporter commented 8 years ago
I think I wrote all essential paramaters (due to documentation), but still get 
this error. Any way to find out which part of request is bad?

Original comment by saeed....@gmail.com on 26 Jan 2012 at 6:51

GoogleCodeExporter commented 8 years ago

Original comment by leont...@google.com on 31 Jan 2012 at 7:45

GoogleCodeExporter commented 8 years ago
I think the problem is that "id" key is specified in event body. I got bad 
request if "id" is present in the body and event inserted successfully if "id" 
was absent. API is supposed to generate "id" itself and return to the caller.

http://code.google.com/apis/calendar/v3/using.html#creating_events

I wasn't using apiKey= parameter though, only OAuth2 request.
Please try inserting the event without pre-defined "id"

service.colors().get().execute() returns 4xx error for me. Investigating.

Original comment by leont...@google.com on 31 Jan 2012 at 8:44

GoogleCodeExporter commented 8 years ago
I removed 'id' and still get Bad Request.

Original comment by saeed....@gmail.com on 1 Feb 2012 at 6:12

GoogleCodeExporter commented 8 years ago
body='{"status": "confirmed", "description": "", "sequence": 0, "visibility": 
"default", "guestsCanModify": false, "calendarId": 
"93mfmsvanup0tllng6tgpm1g88@group.calendar.google.com", "end": {"dateTime": 
"20120123T120839"}, "organizer": {"displayName": "Saeed", "email": ""}, "kind": 
"calendar#event", "attendees": [], "reminders": {"overrides": {"minutes": 0, 
"method": "popup"}}, "summary": "task1", "start": {"dateTime": 
"20120123T110839"}, "etag": "dyMyWqH6pm"}'

Original comment by saeed....@gmail.com on 1 Feb 2012 at 6:13

GoogleCodeExporter commented 8 years ago
(also filled email part)

Original comment by saeed....@gmail.com on 1 Feb 2012 at 6:16

GoogleCodeExporter commented 8 years ago
The following request works for me:

    body = {
        "kind": "calendar#event",
        "description": "My test event",
        "summary": "Test",
        "start": {
          "timeZone": "GMT",
          "dateTime": "2012-01-31T09:00:00"
          },
        "end": {
          "timeZone": "GMT",
          "dateTime": "2012-01-31T10:00:00"
          }
        }

    pprint.pprint(service.events().insert(
        body=body,
        calendarId='primary',
        ).execute())

Note the format of the dateTime.

Original comment by jcgregorio@google.com on 1 Feb 2012 at 2:15

GoogleCodeExporter commented 8 years ago
Thanks, solved.
I saw that time format all around ics files and I supposed that google calendar 
also uses that format.

Original comment by saeed....@gmail.com on 2 Feb 2012 at 9:05

GoogleCodeExporter commented 8 years ago

Original comment by jcgregorio@google.com on 23 Feb 2012 at 6:32