3
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 1 year has passed since last update.

Google スプレッドシートを curl で読む

Last updated at Posted at 2019-03-04

次のシートを読みます。
spread_mar0401.png

curl のスクリプト

curl_read.sh
#
ACCESS_TOKEN="******"
SPREADSHEET_ID="*****"
URL="https://sheets.googleapis.com/v4/spreadsheets/"
#
curl -H "Authorization: OAuth "$ACCESS_TOKEN \
	-X GET \
	$URL$SPREADSHEET_ID/values/Sheet1!A1:E1

実行結果

$ ./curl_read.sh 
{
  "range": "Sheet1!A1:E1",
  "majorDimension": "ROWS",
  "values": [
    [
      "t2001",
      "小山",
      "71345",
      "FALSE",
      "2017-3-15"
    ]
  ]
}

Httpie のスクリプト

http_read.sh
ACCESS_TOKEN="******"
SPREADSHEET_ID="*****"
URL="https://sheets.googleapis.com/v4/spreadsheets/"
#
http GET $URL$SPREADSHEET_ID/values/Sheet1!A1:E1 \
	"Authorization: OAuth "$ACCESS_TOKEN
#

実行結果

$ ./http_read.sh 
HTTP/1.1 200 OK
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Cache-Control: private
Content-Encoding: gzip
Content-Type: application/json; charset=UTF-8
Date: Fri, 04 Aug 2023 05:38:03 GMT
Server: ESF
Transfer-Encoding: chunked
Vary: Origin, X-Origin, Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 0

{
    "majorDimension": "ROWS",
    "range": "Sheet1!A1:E1",
    "values": [
        [
            "t2001",
            "小山",
            "71345",
            "FALSE",
            "2017-3-15"
        ]
    ]
}

アクセストークンの作成方法はこちら

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

スプレッドシートの ID

ファイルを開いた時の URL の 'd/' と '/edit' の間です。
image.png

参考ページ

Google Sheets > API v4 > Basic Reading

3
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
3
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?