0

I have been all over SO and SE looking for the particular answer to this question and cannot seem to find the answer. I am building a simple web application that uses Python Flask to access Google Calendar and fill out the calendar based on conditions. My issue is with OAuth2 and getting the redirect_uris correct. Below is my code, and every time I try to run my code I get an error that the redirect URI is incorrect and the app will not go any further. The redirect uri it seems to be obsessed with is http://localhost:8080. I have tried setting adding that redirect URI to my developers console, adding that URI with a tailing '/oauth2callback' (with and without a tailing '/'). I have also tried specifying a different URI entirely, but the error keeps mentioning http://localhost:8080 and never seems to recognize any other redirect URI despite using different client_secret.json files and specifying other uri's in flow_from_client_secrets. I have also cleared my cache before running the script every time as well as running things in chrome's incognito mode. Nothing seems to help. I know it must be something simple, and if somebody could point out what it was, I would be very appreciative!

SCOPES = 'https://www.googleapis.com/auth/calendar'
CLIENT_SECRET_FILE = 'client_secret_web.json'
APPLICATION_NAME = 'Example Calendar Application'
REDIRECT_URI = 'http://placeholder.com/oauth2callback'

home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    redirect_uri=""
    credential_path = os.path.join(credential_dir,
                                   'calendar-python-quickstart.json')

    store = Storage(credential_path)
    credentials = store.get()
    flow = client.flow_from_clientsecrets(self.CLIENT_SECRET_FILE, 
    self.SCOPES, prompt='consent', redirect_uri=self.REDIRECT_URI)
    flow.user_agent = self.APPLICATION_NAME
    if self.flags:
        credentials = tools.run_flow(flow, store, self.flags)
    else: # Needed only for compatibility with Python 2.6
        credentials = tools.run(flow, store)

        print('Storing credentials to ' + credential_path)
    return credentials
1
  • is there anyone who can answer this? I'm honestly banging my head against the wall and have been for quite some time. Still haven't been able to track down an answer that works. Commented Jan 4, 2018 at 20:24

1 Answer 1

1

I think you have to delete the file created at ~/.credentials/calendar-python-quickstart.json so the program ask for permissions again

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.