Upload file to Google Drive, Raspbian, command line

To upload file do the following steps:

Turn on less secure apps at:
To upload file via command line you have to create trustable applicaiton via web interface!
To do it so go to:
Create a new project:
Enter project name and press [Create]:
Click on [Enable and manage APIs]:
Go for [Drive API]:
Enable API:
Go to Credentials screen:
You want to set up [Client ID] at this time:
Click [Configure consent screen]:
Enter [Product name shown to users]:
Set application type:
now you can see your authentification string and secret:
Download json file:
Upload your "json" to /home/pi

Rename the file to client_secrets.json:
cd ~
mv client_secret*json client_secrets.json
Download python upload code and config file:
wget https://github.com/jerbly/motion-uploader/raw/04de61ce2c379955acac6a2bee676159882d9a86/uploader.py -O uploader.py
wget https://github.com/jerbly/motion-uploader/raw/04de61ce2c379955acac6a2bee676159882d9a86/uploader.cfg -O uploader.cfg
Here is copy of:
Set python script executable:
chmod +x uploader.py
Set username and pasword into config file. Replace red:
sed -i "s/gmailusername/myusername/" uploader.cfg
sed -i "s/gmailpassword/mypassword/" uploader.cfg
Set upload folder to test and turn off email messages:
sed -i "s/folder = motion/folder = test/" uploader.cfg
sed -i "s/send-email = true/send-email = no/" uploader.cfg
Please create "test" directory into your google drive!
If you miss this step nothing will work!

Create new sample file to upload:
echo Hello, Google Drive > hello.drive.log
Test the upload:
./uploader.py uploader.cfg hello.drive.log
If you get something like this:
Traceback (most recent call last):
  File "./uploader.py", line 21, in <module>
    import httplib2
ImportError: No module named httplib2
Install python pip package:
sudo apt-get install python-pip -y
Use pip to install google-api-python-client:
sudo pip install --upgrade google-api-python-client
Run again:
./uploader.py uploader.cfg hello.drive.log
You will receive something like this:
Go to this link in your browser:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&redirect_uri=urn%3Aietf%3Awg%tent.com&access_type=offline
Enter the auth code:
Now you go to the link:
Now copy a code:
When you enter the code this will create file /home/pi/uploader_credentials.txt
As long as this file are there you will no longer will be asked to enter code!

No comments: