Introduction: Google Drive Support for OwnCloud on Raspberry Pi
So you just built your cloud server, and it's working great, but there's one problem. You have a ton of data stored at other locations! What can you do now? The Raspberry Pi is pretty slow, and it's a total pain to download all the files from somewhere else and re-upload them really slowly. Well, here's the thing, you don't have to! OwnCloud has native support for many different types of external storage, and one of the most commonly used ones in Google Drive. I'm not going to lie, it's not as great as Google's interface, you may have to download files to view them, but it's totally awesome to have all your files in one place especially if you use Google Photos. But if you use Google Photos, why did you build a cloud server? OwnCloud can automatically upload new files through the app!
Just messing around, its definitely a good feature to have.
What you will need:
- One Raspberry Pi Cloud Server (or I guess you could have more than one, if you want)
If you don't have that, see my previous Instructable right here.
- A Google account
- A Computer
- A Dataplicity account (if you built your cloud server according to my Instructable, you will have one, if not I'll include it as a step anyway)
That's it! Let's get on with it and head over to step one!
Step 1: Connect to Your Pi
To begin work on your Pi, you have a few options, the first is to just plug the Pi into a monitor and add programs through the terminal, but this can be a little tedious. What I do and would suggest for anyone is to access the Pi through SSH, which basically means that you are using a computer to access the Pi from your home network. Something to consider is that SSH only provides the terminal, there is no GUI, but this should not be a problem.
As a side note, there is a virus going around the internet known as Mirai, and it infects IOT devices, such as the Raspberry Pi when they are open to the internet and still use the default password. Because of this the Raspberry Pi foundation disabled SSH access by default in the latest OS release. I still have an old copy, so I have used that one to start with SSH enabled, and from there immediately change passwords and update the OS from the terminal. They claim that there is a way to enable SSH by placing a file titled ssh in the boot directory, and that will tell the kernel to turn it on, but I have not figured it out. This means that you may have to connect it to a screen, at least to enable SSH access in raspi-config. For those of you who want to use a SSH client, I use PuTTY, which you can download by clicking the link below
You access the Pi through this program by inserting the Pi's IP address , which can usually be found in your router configuration page, or by running the command ifconfig in the terminal, and then clicking Open. It will warn you of some stuff, but it is your Pi, so you can click yes. Make sure to change the default password immediately if you are using this method.
Step 2: Install Dataplicity
So Dataplicity is a service that allows you to connect with your Pi from anywhere in the world over the internet. It creates a secure shell for you to communicate with the device that is all but identical to the traditional SSH shell, which is another alternative to this method, however, you will potentially find Dataplicity extremely useful for troubleshooting or setup away from your home network.
As you can see in the images above, when you first go on the website you will need to put in your email and run some code on your pi, which can be run over SSH or through the terminal. Once you have run this, you will have a fully functioning terminal with which to control your Pi. Login with su (username) and the (password). Afterwards, provided that all your information is correct, you will be able to do whatever you would normally be able to in the terminal over the internet!
Step 3: Enable External Storage and Open Google Developer's Console
In order to connect OwnCloud to external storage, you first need to go into your server's website, make sure you have an Admin account first! Login, and click on the dropdown in the top left that says files. Click on the Apps tab, and click the Not Enabled Tab once it loads. You should see an app titled "External Storage Support" click enable, and then go into the Admin page. You should see a new option titled "External Storage"
Now click on the "Add Storage" dropdown, and click Google Drive. Don't worry about putting in any of the information, but click the little gear, which will bring you to the Google Developer's Console. Log in to your google account, and the it should ask you to create a project. Title it whatever you want, it doesn't matter.
Step 4: Configure the Googe Drive API
Next, it will take you to a home screen, but you won't be able to start until you add support for the Drive API. To do that, go to the library tab, or click something that says something like Select API's. On the far right, near the top, is the Google Drive API. Select it and click enable. Now it will ask you to create credentials.
Next, you need to add two things to the Authorized Redirect URL's
And the second:
Now Click Create, it may give you a client ID and secret, but it won't work yet, you need to authorize the domain first...
Step 5: Domain Verification
So in order for this entire process to work, you have to verify your domain with Google, otherwise, it won't work. So when you finish adding your credentials there should be a tab that says "Domain Verification". Click "Add Domain" to start. It will ask you for an address, so put in www.xxxxxxxxxxx.dataplicity.io with no trailing slash. Once you continue, it will ask you to verify ownership of the domain by uploading a small HTML file to the website. Of course, we have a cloud server, and we know where everything is stored, so simply upload it to your server, but don't put it in any folders, just leave it and we're going to move it in just a second.
So to move it to where Google expects it to be you need to move the file to /var/www/html/xxxxxxxxxx.html, if you are on Apache, which you are if you followed my Instructable, all we need to do if find the path to the file, which in most cases should be /mnt/clouddrive/Ryan(your username)/files/xxxxxxxxxxx.html(the name of the file you uploaded)
To move it in the terminal you just need to type (or copy)
sudo mv /path/to/owncloud/xxxxxxxxx.html /var/www/html/*
*this is the format for the command, not what you need to input, I will put that below.
or in most cases
sudo mv /mnt/clouddrive/Ryan(your username)/files/xxxxxxxxxxx.html /var/www/html/
Remember that xxxxxxxxx.html is the name of your file, and to keep the trailing slash on the end.
Once all of that is done you can click "Verify Now" in the Webmaster Central page.
One final step to get it all working is to "delete" the HTML file from the server's interface, because it was moved, it thinks it is still there, and once you delete it, it will disappear, don't worry it's not there anymore, so it doesn't even show up in deleted files.
Finally, you can go into the Credentials page, and under Domain Verification type your domain one more time, and it should be added as a trusted domain. If you did everything right, it should all be working just fine.
Step 6: Wrapping Up
We're almost there this is basically it, don't worry! All you have to do now is copy the Client ID and Secret and paste them into their respective categories in the External Storage section of the Admin Page. Paste those into there and click "Grant Access", a new window will open, or something like that, and Google will ask you if you want to allow OwnCloud access to your account. Click "Allow" and you should be redirected back to the Admin Page. If you look under External Storage, the Client ID and Secret should be highlighted green to show that everything is working. If you had trouble getting there at any point along the way, don't be afraid to leave comments below, I'd be happy to help!
On a side note, you may have noticed that I have Dropbox support on my server too. I'm going to try to publish an Instructable every month, so as of right now that is my project for February, so expect that coming in the future! Subscribe to my account to keep up!
We have a be nice policy.
Please be positive and constructive.