← back to AgentAbrams
video/oauth_authorize.py
40 lines
#!/usr/bin/env python3
"""
oauth_authorize.py — One-time OAuth flow for YouTube Data API v3.
Run locally to generate a refresh token. Never commit the token file.
Usage:
python3 video/oauth_authorize.py
Prerequisites:
- client_secret.json in project root (from Google Cloud Console)
- pip install google-auth google-auth-oauthlib
"""
import pickle
from google_auth_oauthlib.flow import InstalledAppFlow
SCOPES = ["https://www.googleapis.com/auth/youtube.upload"]
def main():
flow = InstalledAppFlow.from_client_secrets_file(
"client_secret.json", SCOPES
)
creds = flow.run_local_server(port=0)
with open("youtube_token.pickle", "wb") as f:
pickle.dump(creds, f)
print("OAuth complete. Token saved to youtube_token.pickle")
print(f"Refresh token: {creds.refresh_token}")
print()
print("Store this refresh token in GitHub Secrets as YOUTUBE_REFRESH_TOKEN")
print("NEVER commit youtube_token.pickle or client_secret.json")
if __name__ == "__main__":
main()