How to make Google Drive work for you (for a while at least)

Since Google is always changing how you configure things, I figured I’d post current instructions for creating your own Google Cloud OAuth client and a custom google.provider that uses it.

Background

Since KDE is on Google’s shitlist, the keys in Plasma’s built-in google.provider don’t grant you access to Google Drive. To work around this, you can create your own OAuth Client in Google Cloud console and a custom version of google.provider that uses it.

Caveats

  • It seems that Plasma doesn’t handle token refresh correctly, so this will stop working after a week or so. When that happens, just remove the account from Online Accounts and re-add it. As long as you give it the same name it had before, any existing gdrive: paths should continue to work.

  • I don’t know whether access to other Google APIs work with this setup. I haven’t tested sharing videos to YouTube, and as far as I can tell, Plasma doesn’t do anything with the contacts, calendars, and tasks APIs, despite asking for access to them. (Akonadi seems to do its own thing.)

Instructions

Tested on 2025-05-23 with a normal Google account.

Create a project

  1. Visit https://console.cloud.google.com/.

  2. Open the “object picker” (at the top, next to the Google Cloud logo) and click “New Project” in the upper right of the dialog box that appears.

  3. Name your project whatever you like. I used kio-gdrive. The default location (“No organization”) should be fine.

  4. If this is your first project, GCloud console should switch you to it immediately. If you already had another project selected, you’ll have to switch manually by opening the object picker again and clicking on your new project.

Enable APIs

Once you’re “working in” your new project, use the search box at the top of the screen to search for “API Library”. You’re going to turn on a few APIs that KDE wants to use. I’m just going to list the API names. The easiest way to find them is probably with the search box — no not that search box — the one that says “Search for APIs & Services”. For each one, click on it and then click “Enable”.

  • Contacts API
  • Google Calendar API
  • Google Drive API
  • Google Tasks API
  • YouTube Data API v3

Each time you enable an API, it’ll take you out of the API Library, so you’ll have to click back into it by selecting “Library” from the sidebar. Rinse and repeat!

Set up Auth Platform

  1. Once you’ve got all the relevant APIs enabled, use the search box to search for “Google Auth Platform”. You should see the message “Google Auth Platform not configured yet” — click the “Get started” button below that message.

  2. Now we’re going to pretend that we’re deploying an “App” that will be “Published”, have an “Audience”, require “Support” for “Users”, and other such foolishness. You can pretty much put in whatever you like here. Here’s what I did:

    • App name: KDE Online Accounts
    • User support email: (the email address that google has on file for me)
    • Audience: External
    • Contact Information: (just that same email again)
    • Finish: check the “I agree to…” checkbox
  3. Click “Create”. This takes you back to the “Google Auth Platform” overview.

  4. Select “Audience” from the sidebar. Under “Test users”, click “Add users” and add the login emails of any Google accounts you want to log into from Plasma.

  5. Select “Clients” from the sidebar. At the top, click “Create client”. Select “Desktop app”
    for the application type and give it a name. I used “KDE Online Accounts” again, but you can pick anything you like. Click “Create”.

  6. In the “OAuth client created” dialog, take note of your Client ID and Client secret values. You’ll need to put these in your custom google.provider file.

  7. Select “Data Access” from the sidebar. Click “Add or remove scopes”. In the dialog/sidebar thingy, scroll down to “Manually add scopes”, paste in the following lines, and click “Add to table”:

    https://www.googleapis.com/auth/userinfo.email
    https://www.googleapis.com/auth/userinfo.profile
    https://www.google.com/m8/feeds/
    https://www.googleapis.com/auth/calendar
    https://www.googleapis.com/auth/drive
    https://www.googleapis.com/auth/tasks
    https://www.googleapis.com/auth/youtube.upload
    
  8. Click “Update”, then click “Save”.

Create a custom google.provider

  1. Copy /usr/share/accounts/providers/kde/google.provider to ~/.local/share/accounts/providers/google.provider. Create directories as needed. Open your copy for editing.

  2. Add the Google Drive API’s scope — https://www.googleapis.com/auth/drive — to the list in the <setting type="as" name="Scope"> element. Make sure you quote the URL and put a comma after it. (This is a JSON list, I guess.)

  3. Change value of the <setting name="ClientId"> element to the OAuth 2.0 Client ID you saved earlier.

  4. Change the value of the <setting name="ClientSecret"> element to the OAuth 2.0 Client secret you saved earlier.

  5. If you like, change the value of the <description> element to mention “files” or whatever. (This also helps you tell if Plasma is using your new provider.)

  6. If you have Plasma’s System Settings open, close and reopen it. Then add a Google Account to Online Accounts in the normal way.

Anyway…

I hope folks find this helpful. Let me know if you run into issues or if Google changes where all the settings are yet again!

5 Likes

Personally, I just installed Insync:

It’s affordable, it’s worked faultlessly for me for about 8 years now, and it’s actually better than Google’s own Windows client with the exception of the fact that Insync fully supports Linux.

Recommended.

2 Likes

Thanks, works like a charm. Doing all these steps if you are not used to the Google cloud is a pita, though. Forgot to add the audience, ran into 403 access denied, had to fix. On second try, everything is OK now.

Still curious why Google or KDE named the root folder of my gdrive ‘google3’.

I noticed that too! I’m up to google9 at this point. (You can rename the account in the Online Accounts kcm if you like.)

Could it be that you have 9 projects? I have 3.

Any idea how to programmatically refresh the token? Manually removing and re-adding the account isn’t too bad, but I would like something like a cron job running for either doing this or refreshing the token by other means.

Nah, too easy. :wink:

I have three InSync licenses around actually, but I never used them (got them when they had specials). Maybe time to hunt for the logins and try again.

Running into issues now – I get the ‘expired or invalid access token’, but if I try to remove the account (‘google3’ by clicking DEL in Dolphin’s Network - Google Drive window, I get the same error message, and nothing happens.

How am I supposed to remove the account for later re-adding?

I meant to remove and re-add the account in Online Accounts in System Settings. I posted step-by-step instructions here: Kio-gdrive: using custom google.provider works, but access tokens expire or go missing after a few days - #6 by smammy