I want to use the Google Calendar API for my Django application. I have followed the instructions here: https://karenapp.io/articles/how-to-automate-google-calendar-with-python-using-the-calendar-api/
I have also added the redirect uri's in Google API - seems like a browser tries to open up on the server side (as it does on local, but I am unable to manipulate it as the browser from the server side does not show up). In the terminal I do see "Please visit this URL to authorize this application: https://accounts.google.com/..."
Any ideas on what I can do?
Code in views.py:
import datetime
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
SCOPES = ['https://www.googleapis.com/auth/calendar']
CREDENTIALS_FILE = 'path_to_file/credentials.json'
def get_calendar_service():
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
CREDENTIALS_FILE, SCOPES)
creds = flow.run_local_server(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('calendar', 'v3', credentials=creds)
return service