#๐Ÿ”’ Google calendar API authentication link in Discord Bot

4 messages ยท Page 1 of 1 (latest)

autumn moon
#

Hello, I am working on a project where I would like to use google calendar via discord (using my custom bot), and when playing around google calendar API I found that I have no idea on how to get the authentication link outside the terminal.

To give more context this method essentially saves credentials for google calendar user. The problem appears when in the last line creds = flow.run_local_server(port=0) google's function is executed (flow.run_local_server(port=0). This is an asynchronous function and at first it presents with authentication link in terminal and only after user authenticates the function saves credentials in creds variable. However, I want to get the authentication link to be output as discord message and only after user clicks it there the credentials are saved.

 def main():
  """Shows basic usage of the Google Calendar API.
  Prints the start and name of the next 10 events on the user's calendar.
  """
  creds = None
  # The file token.json stores the user's access and refresh tokens, and is
  # created automatically when the authorization flow completes for the first
  # time.
  if os.path.exists("token.json"):
    creds = Credentials.from_authorized_user_file("token.json", SCOPES)
  # If there are no (valid) credentials available, let the user log in.
  if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
      creds.refresh(Request())
    else:
      flow = InstalledAppFlow.from_client_secrets_file(
          "credentials.json", SCOPES
      )

      creds = flow.run_local_server(port=0)```

I tried using this method:

auth_url, _ = flow.authorization_url()
print(auth_url)```
But in this case, after authenticating it throws me this error (see image in attachment) and I have no clue how to add redirect_uri.

cloud pythonBOT
#

@autumn moon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cloud pythonBOT
#

@autumn moon

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.