Search Unity

Google Drive for Unity3D

Discussion in 'Assets and Asset Store' started by midworld, May 26, 2013.

  1. midworld

    midworld

    Joined:
    Feb 12, 2013
    Posts:
    19
    Google Drive for Unity3D plugin.

    Upload, explore, download files in someone's Google Drive.

    And store your secure data such as score with AppData.

    GitHub: https://github.com/midworld/unity-googledrive

    and Doxygen Docs

    Code (csharp):
    1.  
    2. var drive = new GoogleDrive();
    3. drive.ClientID = "YOUR CLIENT ID";
    4. drive.ClientSecret = "YOUR CLIENT SECRET";
    5.  
    6. // Request authorization.
    7. var authorization = drive.Authorize();
    8. yield return StartCoroutine(authorization);
    9.  
    10. if (authorization.Current is Exception)
    11. {
    12.    Debug.LogWarning(authorization.Current as Exception);
    13.    yield break;
    14. }
    15.  
    16. // Authorization succeeded.
    17. Debug.Log("User Account: " + drive.UserAccount);
    18.  
    19. // Upload a text file.
    20. var bytes = Encoding.UTF8.GetBytes("world!");
    21. yield return StartCoroutine(drive.UploadFile("hello.txt", "text/plain", bytes));
    22.  
    23. // Get all files.
    24. var listFiles = drive.ListAllFiles();
    25. yield return StartCoroutine(listFiles);
    26.  
    27. var files = GoogleDrive.GetResult<List<GoogleDrive.File>>(listFiles);
    28. if (files != null)
    29. {
    30.    foreach (var file in files)
    31.    {
    32.        // Download a text file and print.
    33.        if (file.Title.EndsWith(".txt"))
    34.        {
    35.            var download = drive.DownloadFile(file);
    36.            yield return StartCoroutine(download);
    37.  
    38.            var data = GoogleDrive.GetResult<byte[]>(download);
    39.            Debug.Log(System.Text.Encoding.UTF8.GetString(data));
    40.        }
    41.    }
    42. }
    43.  
    Code (csharp):
    1.  
    2. // Upload score in 'AppData'.
    3. int score = 10000;
    4. var bytes = Encoding.UTF8.GetBytes(score.ToString());
    5.  
    6. // User cannot see 'score.txt'. Only your app can see this file.
    7. StartCoroutine(drive.UploadFile("score.txt", "text/plain", drive.AppData, bytes));
    8.  
     
  2. aristigon2

    aristigon2

    Joined:
    May 6, 2015
    Posts:
    1
    I know this is an older project but thought it would be useful. However, I loaded it up and ran it in the browser. It worked but shortly after my Google account was being hacked. Google is pretty good at not letting known devices access you stuff thankfully. It may not be related but it happened right after I used this.