Getting files from our own google drive with API

https://drive.google.com/file/d/abc123456789xxx/view?usp=sharing
https://drive.google.com/uc?id=abc123456789xxx
bash$ gdown 'https://drive.google.com/uc?id=abc123456789xxx'
cat gdownload.sh #!/bin/bashparam=$1;
fileid=`echo $param | grep -oP '(?<=file/d/).+(?=/view)'`;
echo $fileid;
gdown "$fileid"
sudo apt install python3-pip
bash$ python3 -m pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib testresources
python3 gd.py "fileid"
  1. check if “token.pickle” exists or not. If exists it will try to authenticate with that, and the drive API can be used directly.
  2. If not exists, or invalid, it will try searching for “credentials.json”. The information inside will be used to do “human precheck”. Google does not allow the token to be created without human intervention.
  3. The script either will open your default-browser, and you have to authenticate there, or will only show you the link — if you run from server cli (and you have to copy paste the link manually in browser). If you do the latter option (browser login from different machine), you have to copy paste again the produced link (localhost address) into your server by using curl while the gd.py is running.
  4. If successful, a token.pickle will be produced and next time gd.py is running, it won’t need human intervention anymore. The steps inside gd.py already ensures that token gets refreshed if expired.
  5. Process file ID download and show the progress percentage.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store