Gists
This is a sample curl command for uploading a video file to YouTube with the resumable upload using YouTube API.
In order to upload a video file to YouTube with the resumable upload using YouTube API, the following 2 processes are required to be done. The basic process of the resumable upload for YouTube is the same with Drive API. Ref So, I think that this document of Drive API might be useful for understanding the resumable upload process.
Gists
This is the sample scripts for creating new event with Google Meet link to Google Calendar using various languages. When I saw the official document of “Add video and phone conferences to events”, in the current stage, I can see only the sample script for Javascript. But I saw the several questions related to this for various languages. So I published the sample scripts for creating new event with Google Meet link to Google Calendar using various languages.
Gists
When the shared files on Google Drive is downloaded, it is necessary to change the download method by the file size. The boundary of file size when the method is changed is about 40MB.
File size < 40MB
CURL
filename="### filename ###"
fileid="### file ID ###"
curl -L -o ${filename} "https://drive.google.com/uc?export=download&id=${fileid}"
File size > 40MB
When it tries to download the file with more than 40MB, Google says to download from following URL.
Gist
These sample scripts are for requesting multipart post using Google Apps Script.
In most cases, the multipart request is used for uploading files. So I prepared 2 sample situations as follows. For each situation, the request parameters are different.
- Upload a file from Google Drive to Slack.
- Convert an excel file to Spreadsheet on Google Drive using Drive API v3.
Multipart post is required for these situations.
1. Uploading Files From Google Drive To Slack
Curl Code
In order to use this sample, please retrieve access token for uploading file to Slack.
This method was updated at July 12, 2017.
In order to use this, at first, please retrieve your access token and enable Drive API.
1. File ID
Retrieve file id from file name.
curl -X GET -sSL \
-H 'Authorization: Bearer ### Access token ###' \
'https://www.googleapis.com/drive/v3/files?q=name="### FileName ###"&fields=files(id,name)'
Reference : https://developers.google.com/drive/v3/reference/files/list
2. Revision ID
Retrieve revision id from file id.
curl -X GET -sSL \
-H 'Authorization: Bearer ### Access token ###' \
'https://www.googleapis.com/drive/v3/files/### FileID ###/revisions?fields=revisions(id%2CmodifiedTime)'
Reference : https://developers.google.com/drive/v3/reference/revisions/list
I introduce 2 kinds of methods. One is to use curl. Another is to use wget. At this time, I could know that wget can be also used as same as curl.
In order to use this, at first, please retrieve your access token and enable Drive API.
1. File ID
Retrieve file id from file name.
curl -X GET -sSL \
-H 'Authorization: Bearer ### Access token ###' \
'https://www.googleapis.com/drive/v3/files?q=name="### FileName ###"&fields=files(id,name)'
wget -q --header='Authorization: Bearer ### Access token ###' \
'https://www.googleapis.com/drive/v3/files?q=name="### FileName ###"&fields=files(id,name)' \
Reference : https://developers.google.com/drive/v3/reference/files/list
It is necessary to retrieve access token on Google. Scope is as follows.
https://www.googleapis.com/auth/drive
Other mimetypes can be seen here.
Download and convert from Spreadsheet to Excel
curl -X GET -sSL \
-H "Authorization: Bearer [Your access token]" \
-o "Excel file name" \
"https://www.googleapis.com/drive/v3/files/[File ID]/export?mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Upload and convert from Excel to Spreadsheet
curl -X POST -sSL \
-H "Authorization: Bearer [Your access token]" \
-F "metadata={ \
name : '[File name on Google Drive]', \
mimeType : 'application/vnd.google-apps.spreadsheet' \
};type=application/json;charset=UTF-8" \
-F "file=@[Your Excel file];type=application/vnd.ms-excel" \
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
I made One Liner Code to retrieve data using Netatmo API. There are 2 ways. One is for windows dos. Another is for unix bash. Requirement tools are curl and jq.
windows dos
> setlocal & curl -s -d "grant_type=password&client_id='#####'&client_secret='#####'&username='#####'&password='#####'&scope=read_station" "https://api.netatmo.net/oauth2/token" | for /f "usebackq tokens=*" %a in (`jq -r ".access_token"`) do @set a="%a" | curl -s -d "access_token=%a&device_id='#####'" "https://api.netatmo.net/api/getstationsdata" > dat.txt & for /f "usebackq tokens=*" %b in (`jq -r ".body.devices[0].dashboard_data.Temperature" dat.txt`) do @set b="%b" | echo: & set /p nb=Indoor: Temperature %b [degree C],<nul & for /f "usebackq tokens=*" %b in (`jq -r ".body.devices[0].dashboard_data.Humidity" dat.txt`) do @set b="%b" | set /p nb=Humidity %b [%],<nul & for /f "usebackq tokens=*" %b in (`jq -r ".body.devices[0].dashboard_data.Pressure" dat.txt`) do @set b="%b" | set /p nb=Pressure %b [hPa]<nul & for /f "usebackq tokens=*" %b in (`jq -r ".body.devices[0].modules[0].dashboard_data.Temperature" dat.txt`) do @set b="%b" | echo: & set /p nb=Outdoor: Temperature %b [degree C],<nul & for /f "usebackq tokens=*" %b in (`jq -r ".body.devices[0].modules[0].dashboard_data.Humidity" dat.txt`) do @set b="%b" | set /p nb=Humidity %b [%]<nul & del dat.txt
Indoor: Temperature 12 [degree C], Humidity 56 [%], Pressure 1000.2 [hPa]
Outdoor: Temperature 12.3 [degree C], Humidity 56 [%]
unix bash
$ curl -s -d "grant_type=password&client_id='#####'&client_secret='#####'&username='#####'&password='#####'&scope=read_station" "https://api.netatmo.net/oauth2/token"|curl -s -d "access_token=`jq -r '.access_token'`&device_id='#####'" "https://api.netatmo.net/api/getstationsdata"|jq -r '"\nIndoor: Temperature "+(.body.devices[0].dashboard_data.Temperature|tostring)+" [degree C], Humidity "+(.body.devices[0].dashboard_data.Humidity|tostring)+" [%], Pressure "+(.body.devices[0].dashboard_data.Pressure|tostring)+" [hPa]\nOutdoor: Temperature "+(.body.devices[0].modules[0].dashboard_data.Temperature|tostring)+" [degree C], Humidity "+(.body.devices[0].modules[0].dashboard_data.Humidity|tostring)+" [%]"'
Indoor: Temperature 12 [degree C], Humidity 56 [%], Pressure 1000.2 [hPa]
Outdoor: Temperature 12.3 [degree C], Humidity 56 [%]
If you want to use these One Liner Codes, you can use following code. Please replace “#####” to yours.