0

The django app runs on the local server, but does not work on the remote. The server does not have a GUI and does not provide the user with a link to authorization. The server outputs link to the console.

from __future__ import print_function
from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools
import datetime
import os
import json

SCOPES = 'https://www.googleapis.com/auth/calendar'
from .models import Aim

try:
 import argparse
 flags = tools.argparser.parse_args([])
except ImportError:
 flags = None

def calendar_authorization(username):
 store = open('app/static/secret_data/' + username +'.json', 'w')
 store.close()
 store = file.Storage('app/static/secret_data/' + username +'.json')
 creds = store.get()
 if not creds or creds.invalid:
  flow = client.flow_from_clientsecrets('app/client_secret.json', SCOPES)
  flags.noauth_local_webserver = True
  print("________flow_______")
  print(flow.__dict__)
  creds = tools.run_flow(flow, store, flags)
  print("________creds_______")
  print(creds.__dict__)

In the local version, I use client_secret.json, obtained from OAuth 2.0 client IDs. I suspect that I may have the wrong settings for this. I found the information to use the Service account keys(I don't use it now). But I didn’t find a good setup guide for this.

How to set it up and paste in the code for authorization( I did not understand how the access service key is used in the code?)? What could be wrong?

  • While getting the credentials you must have put `http://localhost:8000` or `http://127.0.0.1:8000` in authorized callback url then Update the URI's with the remote url. – Mohit Solanki Feb 09 '19 at 15:36
  • I should add redirect_uri = http://localhost:8000? flow = client.flow_from_clientsecrets('app/client_secret.json', SCOPES, redirect_uri = redirect_uri)? – Olya Pestereva Feb 09 '19 at 16:03

0 Answers0