Google API - nomrand/__basics GitHub Wiki
Google Photo API (REST I/F API)
Get Application Code
Ref. https://int128.hatenablog.com/entry/2018/06/06/234653
access url bellow by browser
https://accounts.google.com/o/oauth2/v2/auth?client_id=XXXXCLIENT_IDXXXX&response_type=code&scope=https://www.googleapis.com/auth/photoslibrary&redirect_uri=urn:ietf:wg:oauth:2.0:oob
URL | https://accounts.google.com/o/oauth2/v2/auth |
---|---|
client_id | XXXXCLIENT_IDXXXX |
response_type | code |
scope | https://www.googleapis.com/auth/photoslibrary |
redirect_uri | urn:ietf:wg:oauth:2.0:oob (means browser login?) |
after that, returned "Application Code" in the browser screean.
then, do curl command bellow in terminal. https://curl.trillworks.com/#node may help
Get Tokens (Access Token/Refresh Token)
curl -X POST --data 'code=XXXXAPPLI_CODEXXXX&client_id=XXXXCLIENT_IDXXXX&client_secret=XXXXCLIENT_SECRETXXXX&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code' https://www.googleapis.com/oauth2/v4/token
URL | https://www.googleapis.com/oauth2/v4/token |
---|---|
code | XXXXAPPLI_CODEXXXX |
client_id | XXXXCLIENT_IDXXXX |
client_secret | XXXXCLIENT_SECRETXXXX |
redirect_uri | urn:ietf:wg:oauth:2.0:oob (means browser login?) |
grant_type | authorization_code |
after that, returned "tokens JSON(access_token,refresh_token,...)" in the response body.
Upload Picture
curl -v --upload-file XXXXUPLOAD_FILEXXXX -X POST -H 'Content-type: application/octet-stream' -H 'X-Goog-Upload-File-Name: XXXXUPLOAD_FILEXXXX' -H 'Authorization: Bearer ${access_token}' https://photoslibrary.googleapis.com/v1/uploads
Headers | xxx |
---|---|
Content-type | application/octet-stream |
X-Goog-Upload-File-Name | XXXXUPLOAD_FILEXXXX |
Authorization | Bearer ${access_token} |
URL | https://photoslibrary.googleapis.com/v1/uploads |
---|---|
body | image binary |
after that, returned "upload token of uploaded image" in the response body.
Register Image
curl -v --data '{"newMediaItems":[{"simpleMediaItem":{"uploadToken":"${upload_token}"}}]}' -H 'Content-type: application/json' -H 'Authorization: Bearer ${access_token}' "https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate"