LoginSignup
2
1

Google スプレッドシートを curl で扱う

Last updated at Posted at 2019-03-03

Google スプレッドシートを curl で扱うサンプルです。シートのタイトルを変更します。

実行前

spread_mar0301.png

実行後

spread_mar0302.png

スクリプト

ACCESS_TOKEN と SPREADSHEET_ID は置き換えて下さい。

curl のスクリプト

curl_update.sh
#
ACCESS_TOKEN="******"
SPREADSHEET_ID="******"
#
URL="https://sheets.googleapis.com/v4/spreadsheets/$SPREADSHEET_ID:batchUpdate"
#
curl -H "Authorization: OAuth "$ACCESS_TOKEN \
	-X POST -H "Content-Type: application/json" \
	$URL -d@in01.json
#
in01.json
{
  "requests": [
    {
      "updateSpreadsheetProperties": {
        "properties": {
          "title": "エスペラント語成績表"
        },
        "fields": "title"
      }
    }
  ]
}

Httpie のスクリプト

http_update.sh
#
ACCESS_TOKEN="******"
SPREADSHEET_ID="******"
#
URL="https://sheets.googleapis.com/v4/spreadsheets/$SPREADSHEET_ID:batchUpdate"
#
http POST $URL \
	"Authorization: OAuth "$ACCESS_TOKEN < in01.json
#

アクセストークンは、こちらで作成できます。

OAuth 2.0 Playground

Spreadsheets v3
https://spreadsheets.google.com/feeds/
を選びます。

有効期限は 3600 秒です。

oauth20_aug31.png

セルデータの代入・更新のサンプル

Google スプレッドシートを curl で 代入・更新

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