#!/usr/bin/env python3 # -*- coding: utf-8 -*- #https://note.com/surugawannoebi/n/n6ae44d916fd4 import requests from requests.auth import HTTPBasicAuth def get_dropbox_refresh_token(app_key, app_secret, auth_code): url = "https://api.dropbox.com/oauth2/token" headers = { "Content-Type": "application/x-www-form-urlencoded" } data = { "code": auth_code, "grant_type": "authorization_code", } auth = HTTPBasicAuth(app_key, app_secret) response = requests.post(url, headers=headers, data=data, auth=auth) if response.status_code == 200: tokens = response.json() print("リフレッシュトークン:", tokens.get("refresh_token")) return tokens.get("refresh_token") else: print("エラーが発生しました:", response.json()) return None # App Key, App Secret, 認証コード(アクセスコード)を設定 # APP_KEY = "YOUR_APP_KEY" # APP_SECRET = "YOUR_APP_SECRET" # AUTH_CODE = "YOUR_AUTH_CODE" # https://www.dropbox.com/oauth2/authorize?client_id=np81qqat6atveal&token_access_type=offline&response_type=code APP_KEY = os.getenv('DROPBOX_APP_KEY') APP_SECRET = os.getenv('DROPBOX_APP_SECRET') AUTH_CODE = os.getenv('DROPBOX_AUTH_CODE') refresh_token = get_dropbox_refresh_token(APP_KEY, APP_SECRET, AUTH_CODE)