Giter Site home page Giter Site logo

unity-googledrive's Introduction

Google Drive for Unity3D

Introduction

Google Drive for Unity3D plugin.

You can upload files, explore, download on the Google Drive storage.

This plugin supports PC(Windows and Mac), Android and iOS.

Installation

Step 1: Enable the Google Drive API.

Step 2: Type Your Client ID and Secret to DriveTest.cs.

In the line 40:

drive.ClientID = "YOUR CLIENT ID";
drive.ClientSecret = "YOUR CLIENT SECRET";
  • PC and iOS can use same Client ID and secret.

  • Android doesn't need Client ID and secret.

Step 3: Run the Sample Scene 'DriveTest'.

All done!

Doxygen Docs

here

Demo Downloads

Sample Code

var drive = new GoogleDrive();
drive.ClientID = "YOUR CLIENT ID";
drive.ClientSecret = "YOUR CLIENT SECRET";

// Request authorization.
var authorization = drive.Authorize();
yield return StartCoroutine(authorization);

if (authorization.Current is Exception)
{
   Debug.LogWarning(authorization.Current as Exception);
   yield break;
}

// Authorization succeeded.
Debug.Log("User Account: " + drive.UserAccount);

// Upload a text file.
var bytes = Encoding.UTF8.GetBytes("world!");
yield return StartCoroutine(drive.UploadFile("hello.txt", "text/plain", bytes));

// Get all files.
var listFiles = drive.ListAllFiles();
yield return StartCoroutine(listFiles);

var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);
if (files != null)
{
   foreach (var file in files)
   {
       // Download a text file and print.
       if (file.Title.EndsWith(".txt"))
       {
           var download = drive.DownloadFile(file);
           yield return StartCoroutine(download);
           
           var data = GoogleDrive.GetResult<byte[]>(download);
           Debug.Log(System.Text.Encoding.UTF8.GetString(data));
       }
   }
}

Work with 'App Data':

// Upload score in 'AppData'.
int score = 10000;
var bytes = Encoding.UTF8.GetBytes(score.ToString());

// User cannot see 'score.txt'. Only your app can see this file.
StartCoroutine(drive.UploadFile("score.txt", "text/plain", drive.AppData, bytes));

License

Apache License 2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.