Files
blog-writer/scripts/get_token.py
T
sinmb79 15eb007b5a Initial commit: 블로그 자동 수익 엔진 v2
- 수집봇: Google Trends, GitHub Trending, HN, Product Hunt, RSS 수집
  + 품질 점수(0-100) 시스템 + 6가지 폐기 규칙
- 발행봇: Blogger API v3 자동 발행 + 안전장치(팩트체크/위험키워드)
- 링크봇: 쿠팡 파트너스 HMAC 서명 + 자동 링크 삽입
- 분석봇: 색인률/CTR/14일성과 등 5대 핵심 지표 + Telegram 리포트
- 이미지봇: manual/request/auto 3가지 모드
  request 모드 — 주기적 프롬프트 전송 → Telegram으로 이미지 수령
- 스케줄러: APScheduler + Telegram 봇 명령 리스너

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 06:54:43 +09:00

60 lines
2.0 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',
]
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:
flow = InstalledAppFlow.from_client_secrets_file(CREDENTIALS_PATH, SCOPES)
creds = flow.run_local_server(port=0)
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()