Coder Social home page Coder Social logo

google-calendar-api-python's Introduction

Google Calendar API Using Python

Want to integrate google calendar api in your application? Link

At the end you will know how to create, update, delete the calendars and events.

Prerequisites [link]

  • Create Google Cloud Platform project with the google calendar API enabled and download the client json file by creating OAuth Credentials. (googleconsolecloudlink)
  • Save the client json file in your working directory.
  • A Google account with Google Calendar enabled.

Step 1: Install the Google client library

 pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

Step 2: Configure the sample

  • In your working directory, create a file name google.py file.
  • To include code in it check out the repo above or the link (configure the sample)

Step 3: Creating service to create google calendar api

  • While creating service you need to add scope.
  • scope - Access that should be given to the user (link)
  • In our project we are giving read, write action to the user

Step 4: Create,Update,Delete Calendar

Create the Calendar (Create)

#Supplying the required calendar info in request_body

request_body = {
    'summary': 'calendarSummary', #Calendar Title
    'timeZone': 'Asia/Kolkata'
}

#returning the request_body in response
response = service.calendars().insert(body=request_body).execute()

Update the Calendar (Update)

#retrieve the calendar you want to update
# here i retrieved the required calendar as myCalendar

myCalendar['summary'] = 'new summary'
myCalendar['description'] = 'new description'

service.calendars().update(calendarId = myCalendar['id'],body =myCalendar).execute()

#check out calendar_update.py file for better explanation.

Delete the Calendar (Delete)

service.calendars().delete(calendarId='id_of_calendar_to_delete').execute()

Step 5: Create, Update, Delete Event

Create Event

Below is the code of the project, you can add more body request for event. Create event

#id of the project
calendar_id_proj = '...'

#----------request body of event-----------#


event_request_body = {
    'start':{
        'dateTime': convert_to_RFC_datetime(2022,2,13,2 ),  #(yyyy,mm,dd,time)
        'timeZone' : 'Asia/Kolkata'
    },

    'end':{
        'dateTime': convert_to_RFC_datetime(2022,2,13,3),  
        'timeZone' : 'Asia/Kolkata'
    },

    'summary': 'MLProj Meet',
    'description':'discussion of the final yr project',
    'colorId': 5,
    'Status': 'confirmed',
    'transparency':'opaque',
    'visibility':'private',
    'location':'Thane, Viviana',
    'attendees':[
        {
            'displayName' : 'Tom',
            'comment' : 'cool guy',
            'email' : '[email protected]',
            'optional': False, #optional: means whether this attendee is optional or not
            'organizer': True,
            'responseStatus': 'accepted'
        }
    ]

}

maxAttendees = 5
sendNotification = True
sendUpdates = 'none'

#-----------Creating Event------------#

response = service.events().insert(    
    calendarId = calendar_id_proj,
    maxAttendees =maxAttendees,
    sendNotifications=sendNotification,
    sendUpdates=sendUpdates,
    body=event_request_body,
).execute()

Update Event (Link)

calendar_id = '...'
eventId = '...'
# First retrieve the event from the API.
event = service.events().get(calendarId=calendar_id, eventId=EventId).execute()

event['summary'] = 'Project Meet'
.
.

updated_event = service.events().update(calendarId=calendar_id, eventId=EventId, body=event).execute()

Delete Event (Link)

calendar_id = '...'
EventId = '...'

service.events().delete(calendarId=calendar_id, eventId=EventId).execute()

google-calendar-api-python's People

Contributors

balirampansare avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

totoro2205

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.