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"
]
]
}
アクセストークンの作成方法はこちら
スプレッドシートの ID
ファイルを開いた時の URL の 'd/' と '/edit' の間です。