Compiling and Running gDrive

In this tutorial, we will be showing you how to compile and use gDrive. gDrive is a command-line tool for interacting with Google Drive.

Compiling and Running gDrive

gDrive is a handy tool for uploading files to Google Drive through the command line. It is relatively simple to use once you have it set up on your device.

This guide will show you how to compile the gDrive software for the Raspberry Pi using your own Google credentials.

Even though this guide focuses on the Raspberry Pi, you can compile gDrive for most operating systems by following the same steps.

By using your own Google credentials, you will be less likely to run into errors like “Sign in with Google temporarily disabled for this app“.

Setting up the Go Compiler

Before we can compile the gDrive software on our device, we must first install the Go compiler.

If you are doing this on a Windows or macOS device, then you can grab the relevant installers from the Golang website.

1. However, if you are doing this tutorial on a Linux based  system like Raspbian, the steps get a bit more involved.

On the terminal on your Linux system, run one of the following commands. These commands differ depending on what architecture you are using.

Linux ARMv6 (Use this for a Raspberry Pi)

wget https://dl.google.com/go/go1.13.7.linux-armv6l.tar.gz -O go.tar.gz

Linux 64-bit

wget https://dl.google.com/go/go1.13.7.linux-amd64.tar.gz -O go.tar.gz

2. With the Go binaries downloaded,  we need to now extract it to the /usr/local/ directory.

Run the following command on your device.

sudo tar -C /usr/local -xzf go.tar.gz

3. Our next step is to get the terminal to interact with Go.

We can do this by modifying the bash aliases file. This file is automatically executed by Bash and will load in our new paths.

nano ~/.bashrc

4. To the bottom of this file, add the following two lines.

These two lines will allow us to run the compiler straight from the command line without having to reference its path directly.

export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin

5. Now save the file by pressing CTRL + X followed by Y then ENTER.

6. To load in the changes to the bashrc file without having to restart, run the following command.

source ~/.bashrc

Retrieving your Google Drive API Credentials

Before we proceed to compile the gDrive software we need to retrieve your Google Drive API Credentials.

1. Begin by going to the “Create Project Page” in the Google Developer Console.

On this page, you need to enter a name for your project (1.). For our example, we will be using the name “gDrive-pimylifeup“.

Create Google API Project

2. Next, we need to enable the Google Drive API for our new project.

We can do that by going to the Google Drive API page within the Google Cloud console.

On this page, click the ENABLE button.

Enable Google Drive API

3. On the next page you are taken to, click the “Credentials” option in the sidebar (1.).

Next, we need to click the “CONFIGURE CONSENT SCREEN” button (2.).

Google API Configure Consent Screen

4. You will now be asked to pick the “User Type“. Unless you are running an organization, you will need to use the “External” option (1.).

Once selected, begin creating the app by clicking the “Create” button (2.).

OAuth Consent Screen External

5. On this page, you will need to enter a name for your application (1.).

For our example, we will be using the application name “gDrive Pi My Life Up“.

Once you have entered a name for your app, you can save the file by pressing the “Save” (2.) button.

OAuth Consent Screen Config

6. Next, we need to return to the “Credentials” page.

You can use the sidebar to easily get back to the page.
Go to Credentials-Screen

7. On this screen, click the “Create Credentials” button (1.).

In the pop-up that appears, click the “OAuth client ID” button (2.).

Create Credentials Oauth Client ID

8. We now need to select the application type. As none of the options fit what we are using the API for we selected “Other“. (1.)

We then need to enter a name for this application (2.). For this example, we just used the name “gDrive Pi My Life Up“.

Once all the data has been entered, click the “Create” button (3.)

Create OAuth Client ID Screen

9. You should now have both the client id and client secret.

Oauth Client Data Created

Copy both of these values down as you will need them later on in this tutorial.

Compiling gDrive with your API Credentials

To compile gDrive, we will need to get its source code by using git.

Before we do this, we should first install git to our device.

You can download the software from the official Git website, or follow the steps below for Debian based system such as Ubuntu and Raspbian.

1. Before we install git, we need to first update the package list by running the command below.

sudo apt update

2. Now, all we need to do is to run the following command.

sudo apt install git

3. With git installed to your device, run the following command to clone the gdrive code.

git clone https://github.com/gdrive-org/gdrive

4. Our next job is to replace the client secret and client id defined in the code.

Begin this process by changing into the cloned directory and modifying the “handlers_meta.go” file using nano.

cd gdrive
nano handlers_drive.go

5. In this file, find the following lines and replace them with their required data.

You should have both the client id and client secret from the previous section.

Find

const ClientId = "367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com"

Replace With Your own Client ID

const ClientId = "YOURCLIENTID"

Find

const ClientSecret = "1qsNodXNaWq1mQuBjUjmvhoO"

Replace With Your own Client Secret

const ClientSecret = "YOURCLIENTSECRET"

6. With the changes made, save the file by pressing CTRL + X, followed by Y, then ENTER.

7. We now need to run the following command so that the Go compiler retrieves all the additional packages that we require to compile our modified version of gDrive.

go get github.com/prasmussen/gdrive

8. We can now compile gDrive to our device by running the following command.

go build -ldflags '-w -s'

The next few steps will make the file usable within the command line

9. To be able to access the binary by using gdrive in the command line, we need to move the file to /usr/local/bin/.

Run the following command to move the executable file.

sudo mv gdrive /usr/local/bin/gdrive

10. The last thing we need to do is give the gdrive executable execution privileges.

sudo chmod a+x /usr/local/bin/gdrive

Testing gDrive on your Device

1. Let’s now begin testing gDrive by connecting your Google account to the application.

To start this process, we need to use the gdrive command alongside the “list” argument.

gdrive list

2. After running gDrive with the list command, you will be told that authentication is required to continue.

Below the message should be a URL. You will need to go to this URL in a web browser and login using your Google account.

Follow the next few prompts in your web browser until you are given a verification code. Copy this verification code into the terminal and press ENTER.

3. If a list of files is displayed, then you have successfully set up gDrive on your device.

This command also shows you the id for each of your folders, If you want to sync a particular folder, you will need the IDs mentioned here.

4. If you want to try syncing a folder, then you can use the following command.

Replace <DIRECTORY> with the path to where you want the files synced to.

You also need to replace <GOOGLEFOLDERID> with the id of a folder you have retrieved using the grdive list command.

./gdrive sync upload <DIRECTORY> <GOOGLEFOLDERID>

At this point in the guide, you should now have gDrive up and running on your device.

If you are after a tutorial to put gDrive to use, be sure to check out our internet speed monitor guide.

If you have run into any issues with this tutorial, feel free to drop a comment below.

6 Comments

  1. Avatar for Daniel
    Daniel on

    Hello I have a this working on one (raspi) but I want to also get it running on a few other raspi’s. Do I need to set up separate credentials for each Pi or can I use the same one for all of them.

    1. Avatar for Emmet
      Emmet on Editor

      Hi Daniel,

      From memory you should be able to use the same credentials for each device. Unless you are using the gDrive software super heavily you shouldnt run into any limitations.

      Cheers,
      Emmet

  2. Avatar for Kacey
    Kacey on

    7. We now need to run the following command so that the Go compiler retrieves all the additional packages that we require to compile our modified version of gDrive.

    go get github.com/prasmussen/gdrive

    This step seems to be not working anymore. Not sure if I am not doing the steps right or something has changed.

    1. Avatar for Emmet
      Emmet on Editor

      Hi Kacey,

      I tested the tutorial again just then and everything is still working as expected. It’s likely you made a mistake at some point.

      Make sure you are using the “go get” command within the ~/gdrive directory.

      Cheers,
      Emmet

  3. Avatar for Tyler Peak
    Tyler Peak on

    I am having a problem with the last part on syncing the files it isnt clear in the replacing and part.

    1. Avatar for Emmet
      Emmet on Editor

      Hi Tyler,

      I have fixed the final command so that it should be more obvious on how to use the command.

      Thank you for pointing out the mistake.

      Cheers,
      Emmet

Leave a Reply

Your email address will not be published. Required fields are marked *