Google Drive for Unity3D

GoogleDrive Class Reference

Google Drive for Unity3D. More...

List of all members.

Classes

class  AsyncSuccess
 Success result. More...
class  Exception
 Exception with error code. More...
class  File
 File class. More...
struct  RevokeResponse
 Response of 'revoke'.
struct  TokenInfoResponse
 Response of 'tokeninfo'.
struct  TokenResponse
 Response of 'token'.

Public Member Functions

 GoogleDrive ()
 Constructor.
IEnumerator Authorize ()
 Start authorization.
IEnumerator Unauthorize ()
 Unauthorize and remove the saved session.
IEnumerator GetFile (string id)
 Get a file metadata.
IEnumerator ListAllFiles ()
 Get all files.
IEnumerator ListFiles (File parentFolder)
 Get files in a folder with Folder File.
IEnumerator ListFilesByQuery (string query)
 Get files by a searching query.https://developers.google.com/drive/search-parameters
IEnumerator InsertFolder (string title)
 Insert a folder to the root folder.
IEnumerator InsertFolder (string title, File parentFolder)
 Insert a folder to otehr folder.
IEnumerator DeleteFile (File file)
 Delete a file(or folder).
IEnumerator UpdateFile (File file)
 Update file's metadata.You can change Title, Description, MimeType and Parents.
IEnumerator TouchFile (File file)
 Touch a file(or folder).
IEnumerator DuplicateFile (File file, string newTitle)
 Duplicate a file in the same folder.
IEnumerator DuplicateFile (File file, string newTitle, File newParentFolder)
 Duplicate a file in a specified folder.
IEnumerator UploadFile (string title, string mimeType, byte[] data)
 Upload a file to the root folder.
IEnumerator UploadFile (string title, string mimeType, File parentFolder, byte[] data)
 Upload a file.
IEnumerator UploadFile (File file, byte[] data)
 Upload a file.
IEnumerator DownloadFile (File file)
 Download a file content.
IEnumerator DownloadFile (string url)
 Download a file content.

Static Public Member Functions

static T GetResult< T > (IEnumerator async)
 Get the result from AsyncSuccess.
static bool IsDone (IEnumerator async)
 Check the async operation is done.

Properties

string ClientID [get, set]
 Google Drive Application Client ID.
string ClientSecret [get, set]
 Google Drive Application Secret Key.
bool IsAuthorized [get, set]
 Is Google Drive authorized.
string UserAccount [get, set]
 User's E-Mail address.
File AppData [get, set]
 AppData folder.https://developers.google.com/drive/appdata

Detailed Description

Google Drive for Unity3D.


Constructor & Destructor Documentation

GoogleDrive.GoogleDrive ( )

Constructor.


Member Function Documentation

IEnumerator GoogleDrive.Authorize ( )

Start authorization.

Returns:
AsyncSuccess or Exception for error.
        var drive = new GoogleDrive();
        drive.ClientID = "YOUR CLIENT ID"; // unnecessary to Android
        drive.ClientSecret = "YOUR CLIENT SECRET"; // unnecessary to Android

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

        if (authorization.Current is Exception)
        {
            Debug.LogError(authorization.Current as Exception);
            return;
        }

        do something;
IEnumerator GoogleDrive.DeleteFile ( File  file)

Delete a file(or folder).

Parameters:
fileFile.
Returns:
AsyncSuccess or Exception for error.

Delete all files.

        var listFiles = drive.ListAllFiles();
        yield return StartCoroutine(listFiles);
        var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);

        if (files != null)
        {
            for (int i = 0; i < files.Count; i++)
                yield return StartCoroutine(drive.DeleteFile(files[i]));
        }
IEnumerator GoogleDrive.DownloadFile ( File  file)

Download a file content.

Parameters:
fileFile.
Returns:
AsyncSuccess with byte[] or Exception for error.

Download a file and print text.

        var download = drive.DownloadFile(file);
        yield return StartCoroutine(download);

        var data = GoogleDrive.GetResult<byte[]>(download);
        if (data != null)
            print(System.Text.Encoding.UTF8.GetString(data));
IEnumerator GoogleDrive.DownloadFile ( string  url)

Download a file content.

Parameters:
fileDownload URL.
Returns:
AsyncSuccess with byte[] or Exception for error.

Download the thumbnail image.

        if (file.ThumbnailLink != null)
        {
            var download = drive.DownloadFile(file.ThumbnailLink);
            yield return StartCoroutine(drive);

            var data = GoogleDrive.GetResult<byte[]>(download);
            if (data != null)
                someTexture.LoadImage(data);
        }
IEnumerator GoogleDrive.DuplicateFile ( File  file,
string  newTitle 
)

Duplicate a file in the same folder.

Parameters:
fileFile to duplicate.
newTitleNew filename.
Returns:
AsyncSuccess with File or Exception for error.

Copy a file in the same folder.

        string newTitle = someFile.Title + "(2)";
        StartCoroutine(drive.DuplicateFile(someFile, newTitle));
IEnumerator GoogleDrive.DuplicateFile ( File  file,
string  newTitle,
File  newParentFolder 
)

Duplicate a file in a specified folder.

Parameters:
fileFile to duplicate.
newTitleNew filename.
newParentFolderNew parent folder. If it is null then the new file will place in root folder.
Returns:
AsyncSuccess with File or Exception for error.

Copy a file to the root folder.

        StartCoroutine(drive.DuplicateFile(someFile, someFile.Title, null));
IEnumerator GoogleDrive.GetFile ( string  id)

Get a file metadata.

Parameters:
idFile ID.
Returns:
AsyncSuccess with a File or Exception for error.
static T GoogleDrive.GetResult< T > ( IEnumerator  async) [static]

Get the result from AsyncSuccess.

Template Parameters:
TType of result.
Parameters:
asyncAsync routine.
Returns:
Result or null.
        var listFiles = drive.ListFiles(drive.AppData);
        yield return StartCoroutine(listFiles);
        var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);

        if (files != null)
            do something;
IEnumerator GoogleDrive.InsertFolder ( string  title)

Insert a folder to the root folder.

Returns:
AsyncSuccess with File or Exception for error.
        var insert = drive.InsertFolder("new_folder_in_root");
        yield return StartCoroutine(insert);
IEnumerator GoogleDrive.InsertFolder ( string  title,
File  parentFolder 
)

Insert a folder to otehr folder.

Parameters:
parentFolderParent folder.
Returns:
AsyncSuccess with File or Exception for error.
        var insert = drive.InsertFolder("new_folder_in_appdata", drive.AppData);
        yield return StartCoroutine(insert);
static bool GoogleDrive.IsDone ( IEnumerator  async) [static]

Check the async operation is done.

Parameters:
asyncAsync operation.
Returns:
True if the operation is done.
IEnumerator GoogleDrive.ListAllFiles ( )

Get all files.

Returns:
AsyncSuccess with List<File> or Exception for error.

Get all files that you can see.

        var listFiles = drive.ListAllFiles();
        yield return StartCoroutine(listFiles);
        var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);
IEnumerator GoogleDrive.ListFiles ( File  parentFolder)

Get files in a folder with Folder File.

Parameters:
parentFolderFolder File.
Returns:
AsyncSuccess with List<File> or Exception for error.

Get all files located directly under AppData.

        var listFiles = drive.ListFiles(drive.AppData);
        yield return StartCoroutine(listFiles);
        var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);
IEnumerator GoogleDrive.ListFilesByQuery ( string  query)

Get files by a searching query.https://developers.google.com/drive/search-parameters

Parameters:
queryQuery string.
Returns:
AsyncSuccess with List<File> or Exception for error.

Search by title.

        var listFiles = drive.ListFilesByQuery("title = 'some_title.txt'");
        yield return StartCoroutine(listFiles);
        var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);

        if (files != null && files.Count > 0)
            do something;
IEnumerator GoogleDrive.TouchFile ( File  file)

Touch a file(or folder).

Parameters:
fileFile to touch.
Returns:
AsyncSuccess with File or Exception for error.
        StartCoroutine(drive.TouchFile(someFile));
IEnumerator GoogleDrive.Unauthorize ( )

Unauthorize and remove the saved session.

Returns:
AsyncSuccess or Exception for error.
        StartCoroutine(drive.Unauthorize());
IEnumerator GoogleDrive.UpdateFile ( File  file)

Update file's metadata.You can change Title, Description, MimeType and Parents.

Parameters:
fileUpdated file.
Returns:
AsyncSuccess with File or Exception for error.

Rename 'a.txt' to 'b.txt'.

        var listFiles = drive.ListFilesByQuery("title = 'a.txt'");
        yield return StartCoroutine(listFiles);
        var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);

        if (files != null && files.Count > 0)
        {
            files[0].Title = "b.txt";
            yield return StartCoroutine(drive.UpdateFile(files[0]));
        }
IEnumerator GoogleDrive.UploadFile ( string  title,
string  mimeType,
File  parentFolder,
byte[]  data 
)

Upload a file.

Parameters:
titleFilename.
mimeTypeContent type.
parentFolderParent folder. null is the root folder.
dataData.
Returns:
AsyncSuccess with File or Exception for error.

Upload a file in AppData.

        var bytes = Encoding.UTF8.GetBytes("world!");
        StartCoroutine(drive.UploadFile("hello.txt", "text/plain", drive.AppData, bytes));
IEnumerator GoogleDrive.UploadFile ( string  title,
string  mimeType,
byte[]  data 
)

Upload a file to the root folder.

Parameters:
titleFilename.
mimeTypeContent type.
dataData.
Returns:
AsyncSuccess with File or Exception for error.
        var bytes = Encoding.UTF8.GetBytes("world!");
        StartCoroutine(drive.UploadFile("hello.txt", "text/plain", bytes));
IEnumerator GoogleDrive.UploadFile ( File  file,
byte[]  data 
)

Upload a file.

Parameters:
fileFile metadata.
dataData.
Returns:
AsyncSuccess with File or Exception for error.

Upload a file to the root folder.

        var bytes = Encoding.UTF8.GetBytes("world!");

        var file = new GoogleDrive.File(new Dictionary<string, object>
        {
            { "title", "hello.txt" },
            { "mimeType", "text/plain" },
        });

        StartCoroutine(drive.UploadFile(file, bytes));

Update the file content.

        var listFiles = drive.ListFilesByQuery("title = 'a.txt'");
        yield return StartCoroutine(listFiles);

        var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);
        if (files != null && files.Count > 0)
        {
            var bytes = Encoding.UTF8.GetBytes("new content.");
            StartCoroutine(drive.UploadFile(files[0], bytes));
        }

Property Documentation

File GoogleDrive.AppData [get, set]
string GoogleDrive.ClientID [get, set]

Google Drive Application Client ID.

string GoogleDrive.ClientSecret [get, set]

Google Drive Application Secret Key.

Android doesn't need this value.

bool GoogleDrive.IsAuthorized [get, set]

Is Google Drive authorized.

string GoogleDrive.UserAccount [get, set]

User's E-Mail address.


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Properties