Skip to content

Instantly share code, notes, and snippets.

@proffapt
Last active July 14, 2023 15:44
Show Gist options
  • Save proffapt/adbc716a427c036f238e828d8995e1a3 to your computer and use it in GitHub Desktop.
Save proffapt/adbc716a427c036f238e828d8995e1a3 to your computer and use it in GitHub Desktop.
Script to generate `token.json` from `credentials.json` file for gmail enabled google api
import sys
from google_auth_oauthlib.flow import InstalledAppFlow
scopes = [f"https://www.googleapis.com/auth/gmail.{sys.argv[1]}"]
flow = InstalledAppFlow.from_client_secrets_file("credentials.json", scopes)
creds = flow.run_local_server(port=0)
with open("token.json", "w") as token:
token.write(creds.to_json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment