Created
December 1, 2021 20:11
-
-
Save leeyspaul/8799d73131f8a651330286d26598ab4f to your computer and use it in GitHub Desktop.
OAuth2 Testing an API request to Google Calendar API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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