Skip to content

Instantly share code, notes, and snippets.

@leeyspaul
Created Dec 1, 2021
Embed
What would you like to do?
OAuth2 Testing an API request to Google Calendar API
@app.route("/test-api-request")
def test_api_request():
"""Tests an API request to Google Calendar."""
# grab the credentials from our flask session, in production
# you will probably store this in some persistent database per user
credentials = google.oauth2.credentials.Credentials(
**flask.session['credentials'])
# build the Google Calendar service which we use to represent the Google Calendar
# API
gcal = build('calendar', 'v3', credentials=credentials)
# grabs Google Calendar events for the particular user who authorized the app
events_result = gcal.events().list(calendarId='primary',
maxResults=10, singleEvents=True).execute()
# return a JSON response to the front end that shows the results
return {
"msg": "successfully processed request",
"data": events_result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment