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.