- youtube_uploader.py: YOUTUBE_REFRESH_TOKEN/CLIENT_ID/CLIENT_SECRET 환경변수 폴백 추가 (token.json 없는 Docker 환경에서 브랜드 계정 인증 가능) - shorts_config.json: corners_eligible를 실제 블로그 코너명으로 수정 - caption_renderer.py: render_captions() 반환값 누락 수정 - get_token.py: web→installed 타입 변환, port 8080 고정, prompt=consent 추가 - get_youtube_token.py: YouTube 전용 OAuth 토큰 발급 스크립트 (별도 클라이언트) - CLAUDE.md: 프로젝트 개요, 배포 방법, 핵심 파일, YouTube 채널 정보 추가 - publisher_bot.py: 이미지 분산 배치, SEO 검증, 버그 수정 - scheduler.py: 알림 강화, atomic write, 중복 방지, hot reload 개선 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
"""
|
|
Google OAuth2 토큰 발급 스크립트
|
|
실행: python scripts/get_token.py
|
|
결과: credentials.json 필요, token.json 생성, refresh_token 출력
|
|
"""
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
from google_auth_oauthlib.flow import InstalledAppFlow
|
|
from google.oauth2.credentials import Credentials
|
|
from google.auth.transport.requests import Request
|
|
|
|
SCOPES = [
|
|
'https://www.googleapis.com/auth/blogger',
|
|
'https://www.googleapis.com/auth/webmasters',
|
|
'https://www.googleapis.com/auth/youtube.upload',
|
|
'https://www.googleapis.com/auth/youtube',
|
|
]
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
TOKEN_PATH = os.path.join(BASE_DIR, 'token.json')
|
|
CREDENTIALS_PATH = os.path.join(BASE_DIR, 'credentials.json')
|
|
|
|
|
|
def main():
|
|
if not os.path.exists(CREDENTIALS_PATH):
|
|
print(f"[ERROR] credentials.json 파일이 없습니다: {CREDENTIALS_PATH}")
|
|
print("Google Cloud Console에서 OAuth 클라이언트 ID를 생성하고")
|
|
print("credentials.json 을 C:\\blog-engine\\ 에 저장하세요.")
|
|
sys.exit(1)
|
|
|
|
creds = None
|
|
if os.path.exists(TOKEN_PATH):
|
|
creds = Credentials.from_authorized_user_file(TOKEN_PATH, SCOPES)
|
|
|
|
if not creds or not creds.valid:
|
|
if creds and creds.expired and creds.refresh_token:
|
|
creds.refresh(Request())
|
|
print("[OK] 기존 토큰 갱신 완료")
|
|
else:
|
|
# credentials.json이 "web" 타입이면 "installed"로 변환
|
|
with open(CREDENTIALS_PATH) as f:
|
|
client_config = json.load(f)
|
|
if 'web' in client_config and 'installed' not in client_config:
|
|
client_config['installed'] = client_config.pop('web')
|
|
flow = InstalledAppFlow.from_client_config(client_config, SCOPES)
|
|
creds = flow.run_local_server(port=8080, prompt='consent')
|
|
print("[OK] 새 토큰 발급 완료")
|
|
|
|
with open(TOKEN_PATH, 'w') as token_file:
|
|
token_file.write(creds.to_json())
|
|
|
|
token_data = json.loads(creds.to_json())
|
|
refresh_token = token_data.get('refresh_token', '')
|
|
|
|
print("\n" + "=" * 50)
|
|
print("토큰 발급 성공!")
|
|
print("=" * 50)
|
|
print(f"\nREFRESH_TOKEN:\n{refresh_token}")
|
|
print(f"\n이 값을 .env 파일의 GOOGLE_REFRESH_TOKEN 에 붙여넣으세요.")
|
|
print(f"\ntoken.json 저장 위치: {TOKEN_PATH}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|