LoginSignup
0
2

More than 1 year has passed since last update.

Compute Engine から Python でスプレッドシートを参照したい

Last updated at Posted at 2021-07-05

これは

Compute Engine のVMインスタンスからサービスアカウントキーを使用せずに Python を用いてスプレッドシートにアクセスするための備忘録。

前提

GCPプロジェクト、ComputeEngineインスタンスは作成済みとする。

手順

1. 連携に必要なAPIを有効にする

以下のAPIを有効にする。
- Google Drive API
- Google Sheets API

2. ComputeEngineにアクセススコープを付与する

まず、インスタンスを停止する。
次に、Cloud Shellから以下のコマンドを実行する。

$ gcloud beta compute instances set-scopes \
projects/{プロジェクトID}/zones/{VMインスタンスのゾーン}/instances/{VMインスタンス名} \
--scopes default,https://www.googleapis.com/auth/spreadsheets.readonly

3. Pythonスクリプト作成

あとで書きます。

参考にさせていただいた記事

https://qiita.com/Sekky0905/items/e1ae602a1a2a4edb17df
https://stackoverflow.com/questions/64937670/accessing-google-sheets-api-from-google-compute-engine-python
https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances?hl=ja

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2