Skip to content

Instantly share code, notes, and snippets.

@leeyspaul
Created December 1, 2021 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeyspaul/8799d73131f8a651330286d26598ab4f to your computer and use it in GitHub Desktop.
Save leeyspaul/8799d73131f8a651330286d26598ab4f to your computer and use it in GitHub Desktop.
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