2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Google SpreadSheetのデータを`curl`コマンドで取得する

2
Posted at

Google SpreadSheetのデータをcurlコマンドで取得するための備忘メモ

1.Google SpreadSheetにアクセスできるようにしておく

2021/12/28時点では、スプレッドシートID、シート名、APIキーが必要らしい。
以下を参照して、Google SpreadSheetにアクセスできるようにしておく

【最新版】Google SpreadSheetのデータをJSONで取得する手順
https://sheets.googleapis.com/v4/spreadsheets/{スプレッドシートID}/values/{シート名}?key={APIキー}

③:専用URLにアクセスする
JSON取得URL【テンプレート】

事前に、https://docs.google.com/forms/u/0/からgoogle form(質問と回答)とスプレッドシートを作成しておくとよい

2.コマンドラインから取得できるようにする

1.を設定した後、以下を実行すればOK

curl https://sheets.googleapis.com/v4/spreadsheets/{スプレッドシートID}/values/{シート名}?key={APIキー} -o result.json

400(Bad Request)エラーが返る

入力パラメータである、スプレッドシートID、シート名、APIキーが間違っている可能性がある。
(自分の場合はシート名が間違っていた)

{
  "error": {
    "code": 400,
    "message": "Unable to parse range: sheet",
    "status": "INVALID_ARGUMENT"
  }
}

404 not foundエラーが返る

URLがそもそも間違っているので、1から見直しが必要。

参考

【最新版】Google SpreadSheetのデータをJSONで取得する手順
https://docs.google.com/forms/u/0/
gsutil をインストールする
Google Formsの回答データをスプレッドシートからダウンロード
Google spreadsheetの値を取得する

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?