I have a Django app that access data from Google Tag Manager using its API. It works fine locally, but when it is deployed and I try to authenticate, I get this message:
UserWarning: Cannot access tagmanager.dat: No such file or directory
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%...........
If your browser is on a different machine then exit and re-run this
application with the command-line parameter
--noauth_local_webserverAnd the browser doesn't open a new window for authentication which leads to a timeout error.
views.py
import argparse
import sys
import os
import httplib2
from apiclient.discovery import build
from oauth2client import client
from oauth2client import file
from oauth2client import tools
import pandas as pd
def GetService(api_name, api_version, scope, client_secrets_path):
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[tools.argparser])
flags = parser.parse_args([])
credentials = run_flow(flow, storage, args)
flow = client.flow_from_clientsecrets(
client_secrets_path, scope=scope,
message=tools.message_if_missing(client_secrets_path))
storage = file.Storage(api_name + '.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run_flow(flow, storage, flags)
http = credentials.authorize(http=httplib2.Http())
service = build(api_name, api_version, http=credentials.authorize(http=httplib2.Http()))
return serviceI have also tried to add flags.noauth_local_webserver = True as suggested here, but no luck.
My API configuration is as follows:
Client ID for Web Application
Authorised JavaScript origins URI: https://myapp.appspot.com Authorised redirect URIs: https://myapp.appspot.com/accounts/google/login/callback/
I am not sure about the API configuration and the Google docs are absolutely useless on this matter.
Other questions on Stackoverflow are either too old or not related to this. I have also deployed it to Heroku, but I have the same issue there too
How do I fix this issue?