Gandi
Gandi

Reputation: 3652

How can I edit a secondary calendar using google python API

I wonder if it's possible to create and delete events with Google API in a secondary calendar. I know well how to do it in main calendar so I only ask, how to change calendar_service to read and write to other calendar.
I've tried loging with secondary calendar email, but that's not possible with BadAuthentication Error. The URL was surely correct, becouse it was read by API.
Waiting for your help.

Upvotes: 2

Views: 1420

Answers (2)

Gandi
Gandi

Reputation: 3652

A'm answering my own question so I can finally accept this one. The problem has been solved some time ago.

The most important answer is in this documentation.

Each query can be run with uri as argument. For example "InsertEvent(event, uri)". Uri can be set manually (from google calendar settings) or automatically, as written in post below. Note, that CalendarEventQuery takes only username, not the whole url.

The construction of both goes this way:

user = "[email protected]"

uri = "http://www.google.com/calendar/feeds/{{ user }}/private/full-noattendees"

What's useful, is that you can run queries with different uri and add/delete events to many different calendars in one script.

Hope someone finds it helpful.

Upvotes: 1

user473489
user473489

Reputation: 116

I got the same issue but I found this solution (I do not remember where)

This solution is to extract the secondary calendar user from its src url provided by google

This is probably not the better one but it's a working one

Note:the code is extracted from a real project [some part has been removed] and must be adapted to your particular case and is provide as sample just to have a support for explaination (It will not work as is)

# 1 - Connect using the main user email address in a classical way

cal_client = gdata.calendar.service.CalendarService()
# insert here after connection stuff

# 2 - For each existing calendars

feed = cal_client.GetAllCalendarsFeed():

# a loop the find the calendar by it's title (cal_title)
for a_calendar in feed.entry:
    if cal_title in a_calendar.title.text:
         cal_user = a_calendar.content.src.split('/')[5].replace('%40','@')
         # If you print a_calendar.content.src.split you will see that the url 
         # contains an email like definition. This is the one to used to work
         # with the calendar 

Then you just have to replace the default user by the cal_user in the api to work on the secondary calendar.

Replace call is required because google api function are doing internal conversion on special characters like '%'

I hope this will help you.

Upvotes: 0

Related Questions