Skip to content
Nate River edited this page Sep 27, 2023 · 73 revisions

Welcome to the Simple Google Drive wiki!

About

The asset consists of 2 parts: Google Sign-in and use of Google Drive API. So let's start!

Features

  • Cross-platform (Android, iOS, macOS, Windows, UWP, WebGL)
  • Simple and flexible code
  • Easy to learn with a lot of examples

Skills required

  • Strong C# knowledge
  • LINQ basics
  • Async programming basics
  • Understanding Google Drive API

Notes / Did you know?

  • Google Drive does NOT behave like your local file system! File and folder names need not be unique, even at a given level of the hierarchy. This means that a single path can describe multiple files.
  • Google Drive operates with entities called File. This can be a file, a folder or a Google Workspace document (Google Docs, Sheets, and Slides). Each file has a MIME type. For example, folders are files with MIME type application/vnd.google-apps.folder and Google Sheets have MIME type application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.
  • Google Drive has a hierarchical structure where each file has a parent, and the root folder is My Drive with ID root.
  • Google Drive API doesn't support paths as we used to work with in Android or Windows, so we have to implement path resolving by iterating through parents and childs (if we want to operate with paths, of course).
  • Google Drive file names are case sensitive, unlike File System names for most platforms.

Simple Google Sign-In

You need to purchase and import Simple Google Sign-In and follow setup steps described in Wiki. IMPORTANT! Add Google Drive API access scope on Google Cloud > APIs & Services > OAuth consent screen. After obtaining a valid access token you can start using Google Drive API.

Scopes (choose one)

  • https://www.googleapis.com/auth/drive.appdata (preferred) allows to work with the app folder only. This is a non-sensitive scope and your app doesn't require to be validated by Google. The application data folder is a special hidden folder that your app can use to store application-specific data, such as configuration files. The application data folder is automatically created when you attempt to create a file in it. Use this folder to store any files that the user shouldn't directly interact with. This folder is only accessible by your application and its contents are hidden from the user and from other Drive apps. Root folder ID is appDataFolder. With this scope, you can't work with Trash or other locations except the app folder. More info: Store application-specific data.
  • https://www.googleapis.com/auth/drive allows to see, edit, create, and delete all Google Drive files avaialble for the current user. This is a restricted scope, so your app should be validated by Google (Google Cloud > APIs & Services > OAuth consent screen). The root folder is My Drive with ID root.

Self-check

  1. You've imported BOTH assets: Simple Google Sign-In and Simple Google Drive.
  2. You've created Google credentials with Google Drive API scope (https://www.googleapis.com/auth/drive).
  3. You've changed credentials in SimpleGoogleSignIn/Resources/Settings
  4. You can sign in with Google and obtain an access token (press Sign-in in the Examples scene). You may see the warning This app isn't verified when signing in to Google, it's because your app uses a restricted scope and wasn't reviewed by Google. It's ok, just press Advanced to continue.

Google Drive API

Your entry point is GoogleDrive class. It contains core functions to work with Google Drive API. GoogleDriveExtensions provides extra methods that can't be related to core functions. The asset includes examples for all basic actions, just refer to Examples scene and scripts inside the Examples folder.

Script reference

Next steps

  • Write a review on the Asset Store =)
  • Remove debug logs with sensitive data (like access tokens), set GoogleDrive.DebugLog = false
  • Add new functions by extending GoogleDrive and GoogleDriveExtensions (or contact me for updating/extending the asset)
  • Send your app for review if you use the restricted scope https://www.googleapis.com/auth/drive. It's not so easy as you may think, so be patient.

Background

I'm a developer of Pixel Studio, a cross-platform drawing app. I use Google Drive to allow users to sync their files across different platforms. I was using Unity Google Drive before, a free asset made by Artyom Sovetnikov (Elring). Finally, I decided to make my own asset, with blackjack and hookers, of course. And stop using Unity Google Drive. There are a lot of reasons:

  • The project is abandoned, the developer doesn't fix issues (they are auto closed by the bot)
  • Very complicated and confusing code, high entry threshold
  • Complicated authorization setup
  • Native plugins and 3rd party libraries
  • Strict mapping to Google Drive API, it's hard to modify or extend the code
  • No support for Universal Windows Platform (UWP) due to outdated authorization method
  • WebGL apps need to be restarted when performing Google auth

Links

Clone this wiki locally