Skip to content

Commit

Permalink
get port of redirect uri from google credentials file
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaofeng Huang committed Oct 2, 2024
1 parent 0491ab7 commit 9cc827d
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Google docs reader."""

import json
import logging
import os
import random
Expand Down Expand Up @@ -112,7 +113,15 @@ def _get_credentials(self) -> Any:
flow = InstalledAppFlow.from_client_secrets_file(
"credentials.json", SCOPES
)
creds = flow.run_local_server(port=0)

port = 8080
with open("credentials.json", "r") as json_file:
client_config = json.load(json_file)
redirect_uris = client_config["web"].get("redirect_uris", [])
if len(redirect_uris) > 0:
port = redirect_uris[0].strip("/").split(":")[-1]

creds = flow.run_local_server(port=port)
# Save the credentials for the next run
with open("token.json", "w") as token:
token.write(creds.to_json())
Expand Down

0 comments on commit 9cc827d

Please sign in to comment.