In part 2 of the Google Tasks API with Python tutorial, II will go through each Tasklists Resource method. So what is a Task list? A task list is a list containing tasks. Users can have more than one task list to manage their tasks the way they want in Google Tasks. Google Tasks is a very popular To-Do app created by Google. Using the Google Tasks API, we can use Python or any other programming languages to search, read, create, and update Google tasks. As someone who has experience using most of the Google APIs, Google Tasks API is probably one of the easiest APIs to use.
Google Tasks API Documentation LINK
Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn
Tasklists_demo.py:
import pandas as pd
from Google import Create_Service, convert_to_RFC_datetime
CLIENT_SECRET_FILE = '<your secret file.json>'
API_NAME = 'tasks'
API_VERSION = 'v1'
SCOPES = ['https://www.googleapis.com/auth/tasks']
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
"""
Tasks Demo: Restaurants To Try:
San Francisco
- Pearl San Francisco
- Burma Superstar
- House of Prime Rib
Chicago
New York
"""
"""
Insert method
"""
tasklistRestaurants = service.tasklists().insert(
body={'title': 'Restaurants to try'}
).execute()
for i in range(100):
service.tasklists().insert(body={'title': 'Tasklst #{0}'.format(i+1)}).execute()
"""
List Method
"""
response = service.tasklists().list().execute()
lstItems = response.get('items')
nextPageToken = response.get('nextPageToken')
while nextPageToken:
response = service.tasklists().list(
maxResults=30,
pageToken=nextPageToken
).execute()
lstItems.extend(response.get('items'))
nextPageToken = response.get('nextPageToken')
print(pd.DataFrame(lstItems).head())
# pd.set_option('display.max_columns', 100)
# pd.set_option('display.max_rows', 500)
# pd.set_option('display.min_rows', 500)
# pd.set_option('display.max_colwidth', 150)
# pd.set_option('display.width', 120)
# pd.set_option('expand_frame_repr', True)
"""
Delete Method
"""
for item in lstItems:
try:
if isinstance(int(item.get('title').replace('Tasklst #', '')), int):
if int(item.get('title').replace('Tasklst #', '')) > 50:
# print(int(item.get('title').replace('Tasklst #', '')))
service.tasklists().delete(tasklist=item.get('id')).execute()
except:
pass
response = service.tasklists().list(maxResults=100).execute()
print(pd.DataFrame(response.get('items')))
"""
Update Method
"""
mainTasklist = response.get('items')[1]
mainTasklist['title'] = 'Restaurants to eat'
service.tasklists().update(tasklist=mainTasklist['id'], body=mainTasklist).execute()
"""
Get Method
"""
print(service.tasklists().get(tasklist='ejl0Yjl5RWZ4cmI1Sk1oeg').execute())