I'm trying to build an authorization function for a command-line tool so that I can authorize a credentials.json file on the command line. I'm getting an error where the console says UserWarning: Cannot access C:\...\token.json: No such file or directory
even though there isn't supposed to be a token.json
file. I run quickstart.py in the same directory as the credentials.json
and it seems to work out just fine, but this doesn't.
Here is the code:
import calendar
import datetime
import json
import pathlib
import os
import pprint
import time
import re
import sys
import click
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
#code omitted for brevity
current_path = pathlib.Path.cwd()
file_path = str(current_path) + '\\' + 'credentials.json'
if os.path.exists(file_path):
if True: #omitted for simplicity
#copy pasta from quickstart.py
store = file.Storage(str(current_path) + '\\token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets(str(current_path) + '\\credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
print('You have been authorized. Feel free to run any commands you would like.')
return 0
Here is the file structure:
project_file
|
L _ _ other_file
| L_ _ file_where_the_above_code_is_located
| L_ _ credentials.json
| L_ _ quickstart.py
|
L setup.py, license, tests, etc