Assuming there are three steps,
- Getting a device code,
- Getting an authentication token,
- Connect to Google Drive.
STEP 1:
I get through Step 1 if (and only if) I ignore the redirect_url
parameter listed necessary on various how-to links. So it's...
curl -d 'client_id=*client_id*' -d 'scope=https://www.googleapis.com/auth/drive.file' -d 'response_type=code' 'https://accounts.google.com/o/oauth2/device/code'
At that point the return is...
{"device_code": "[device_code]", "user_code": "[user_code]", "expires_in": 1800, "interval": 5, "verification_url": "https://www.google.com/device"}
So far so good.
STEP 2: This is where I get stuck. Tried various iterations of the following:
curl -H 'Content-Type: application/x-www-form-urlencoded' -d 'client_id=**client_id**' -d 'client_secret=*client_secret*' -d 'grant_type=authorization_code' -d 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' -d 'code=[device_code_from_above]' 'https://accounts.google.com/o/oauth2/token'
The above returns
{"error" : "invalid_grant", "error_description" : "Malformed auth code."}
If grant_type
is changed to 'http://oauth.net/grant_type/device/1.0'
, response is
{"error" : "invalid_request", "error_description" : "Parameter not allowed for this message type: redirect_uri"}
If redirect_uri
is removed the response is
{"error" : "authorization_pending"}
The above cURL attempts were cobbled together referencing the following links... https://developers.google.com/identity/protocols/OAuth2ForDevices
http://www.visualab.org/index.php/using-google-rest-api-for-analytics#comment-157284
list google drive files with curl
Google Drive not listing files in folder
Not able to fetch Google OAuth 2.0 access token
https://www.daimto.com/google-authentication-with-curl/
Stymied!
EDIT
Per request, the goal here: develop a method of being alerted when files upload, and have a system in place that can selectively and systematically download based on a variety of queries.
The reason we're not doing this with Google Drive's web UI: The file sizes are pretty big: 10-50gb per file, and Google can't batch download without zipping first, and can't zip anything over a size that's smaller than our smallest file.
The reason we're not doing this with Google Drive's APP: It's not possible (AFAIK) to manage which files do and don't download locally, and there's no ability (again AFAIK) to store to an external volume.
Also, we're integrating a workflow database into our media uploads and downloads: tracking, dates, progress notes, versions, etc., none of which is part of any existing Google system. So the goal here is to see what's options Google's API might hold for all this.