====== スプレッドシート ====== ===== このページは ===== Pythonからgoogleスプレッドシート操作した時のmemo。((2016.09.08時点で未完成)) ===== Drive API ===== スプレッドシートは、Google Apps APIのDrive APIを利用して操作する。 [[https://console.developers.google.com/project|Developers Console]]にアクセスして、プロジェクトを選択。\\ プロジェクトが存在しない場合は、適当に作る。 Google Apps API->Drive APIを有効にする 認証情報に進む 認証情報作成->サービスアカウントキー->新しいサービスアカウント:JSON 以下のような形式のjsonファイルが保存されます { "type": "service_account", "project_id": "projectsample", "private_key_id": "abc..........................", "private_key": "-----BEGIN PRIVATE KEY----- ...................................................................................................U0\n-----END PRIVATE KEY-----\n", "client_email": "projectsample@projectsample.iam.gserviceaccount.com", "client_id": "12345678901234567890123", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/.............................." } ===== Pythonのライブラリ ===== 必要なライブラリ * oauth2client * gspread これらをインストールします。 # pip install --upgrade oauth2client # pip install --upgrade gspread ===== 参考 ===== [[http://www.yoheim.net/blog.php?q=20160401|[Python] Google各種サービスのAPIの認証方法(v.2)]] [[https://developers.google.com/identity/protocols/OAuth2ServiceAccount#authorizingrequests|Preparing to make an authorized API call]] http://qiita.com/koyopro/items/d8d56f69f863f07e9378 [[https://developers.google.com/drive/v2/web/quickstart/python#step_2_install_the_google_client_library|Python Quickstart | Drive REST API | Google Developers]]