Can't authenticate Tag Manager API through OAuth in Django when deployed on Google App Engine

166 views
Skip to first unread message

Nicolò Zanellato

unread,
Jun 11, 2020, 5:50:41 PM6/11/20
to Google App Engine

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_webserver

And 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 service

I 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?

Manpreet Sidhu (Google Cloud Support)

unread,
Jun 12, 2020, 10:47:38 PM6/12/20
to Google App Engine
Thanks for reaching out. I suggest that you consider looking into the Tag Manager documentation as that is outside the scope of App Engine.

Even though you suggest that posts on Stack Overflow are no longer relevant, you are always allowed to create a new post. These types of questions are best suited for Stack Overflow. Google Groups are best resources for product discussions and getting information like service status updates and release notes, and ranging from book recommendations to creative shortcuts. You can get more details regarding our community support here.
Reply all
Reply to author
Forward
0 new messages