Search Unity

Google Drive SDK for Unity (free, open-sourced)

Discussion in 'Assets and Asset Store' started by Elringus, Feb 1, 2018.

  1. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Hi! Unfortunately, the team drives API is not yet implemented, but I guess I can work on this right now, so it should be available with the new release today or tomorrow. I'll post an update here when it's ready.
     
  2. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    I've added support for the TeamDrives API. You can download the latest release here: https://github.com/Elringus/UnityGoogleDrive/releases/tag/v0.9-alpha

    Unfortunately, I don't have a TeamDrive subscription and wasn't able to test all the API methods (create, delete, list, get, update). I'll be grateful if you could check them out and let me know whether they're working properly.
     
  3. mikko_forsman

    mikko_forsman

    Joined:
    Jul 10, 2017
    Posts:
    22
    Thank you for the super fast reply! I will try it later today and update you as soon as I can

    -Mikko Forsman
     
  4. mikko_forsman

    mikko_forsman

    Joined:
    Jul 10, 2017
    Posts:
    22
    Seems to be working fine, at least with a really quick test. Thanks again.

    -Mikko
     
    Elringus likes this.
  5. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    I have this same issue. iPhone X 11.3.1

    It does not work on wifi or mobile data...

    I had the same app and same version of the plugin working on the same device in February. So something must have happened on Apple side since.

    All I did was resign the app and build onto the device and suddenly it hangs after browser auth. Auth not going through at all.


    I have updated to latest version on github, tried blanx suggestion of modifying the plist, but nothing.
     
    Last edited: May 15, 2018
  6. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    I'm still not sure why this is happening (can't even reproduce the issue on my own iPhone), but maybe this could be related to the blocking http listener that is used when completing the auth. I've just added a new release; it will use an async http listener when under .NET 4.x scripting runtime and won't block the app when performing the auth. Can you please check whether that will have any effect on the issue? Don't forget to switch to the .NET 4.x runtime before trying this.
     
  7. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    Great, that works! Auth request successful and app gets the response.

    Is there a way to run a callback when the auth request passes.

    Thanks!
     
  8. iamfist

    iamfist

    Joined:
    Aug 27, 2017
    Posts:
    9
    Hi Elringus,

    I had the same problem as Tenebris_Lab and blanx. I could not get the access tokens anymore and only the devices that had already stored access tokens before would work as a result.
    Like the Tenebris_Lab I did not change anything before related to your plugin or my xcode SDK so I am also assuming the newest iOS update did change something.

    However switching to your newest version from yesterday (and switching to .net 4.6) and using blanx' proposed plist changes fixed this problem. I checked on iPhone7, iPhone 8, iPad Pro 2017 and iPad 2017.

    Edit: Also thanks for your great work! Your project really saved me a lot of time.
     
  9. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    Another question if I may.

    I'm not getting any progress value when uploading a file. Its only 0 or 1, any ideas?
     
  10. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Nice, glad it worked after all :)

    Auth requests are executed automatically (if needed) when you're performing any kind of Google Drive API requests, so you can just use them and forget about authentication (at least, that's how it's supposed to work). Therefore, there are no public callbacks of methods for the auth-related things. Is there a reason you need a callback for the auth requests?

    There was a bug in progress tracking; it's fixed now. Thanks for letting me know!
     
    Last edited: May 16, 2018
    Tenebris_Lab likes this.
  11. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    I want to disable a button/gameobject if the client is authenticated. I do this on start and it works great - I asked you about this on GitHub some time ago - by checking the playerpref, but would like to do this when switching back to the app on first time authentication.

    Progress fixed, thanks!
     
  12. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    Might be useful to have an example of File Create for a specific folder. I see you have getting by path.
     
  13. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    How about wrapping some lightweight request specifically for the auth (like, GoogleDrvieAbout.Get) and just disable the gameobject when it's done?

    Well, you can't really create a file in a folder, because a folder in Google Drive is actually a file :) You just create folder like any other files and then add the ID of that file to other file's 'Parent' property. This is explained in the FAQ on GitHub.
     
    Tenebris_Lab likes this.
  14. iamfist

    iamfist

    Joined:
    Aug 27, 2017
    Posts:
    9
    After looking into iOS behavior some more a friend told me that localhost is automatically trusted while 127.0.0.1 is not.
    I could not find a source quickly to back this claim but testing showed this to be true.

    Authentication now works for me on iPhone without modification of plist.info.

    So changing the corresponding line in LoopbackAccessTokenProvider.cs seems to solve this.
    Code (CSharp):
    1. private const string LOOPBACK_URI = @"http://localhost";
     
  15. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Thank you for sharing the info! I've initially used localhost, but then found out, that Google recommends against using the alias for local loopback request due to possible issues with some firewalls:



    So now I'm not really sure what's better. Guess I'll just add an option to the settings so that users can specify loopback URI they want to use and set 'localhost' as the default one.
     
  16. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
  17. iamfist

    iamfist

    Joined:
    Aug 27, 2017
    Posts:
    9
    Thank you for implementing this so fast. Hope this saves new users some frustration :)
     
    Elringus likes this.
  18. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    Hello Elringus.

    I am having an issue where the loopback url does not load on iOS (Have not tested android). Switching back to the app does complete auth, and switching back to the browser then completes loading the loopback response.

    Any ideas?
     
  19. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Can you please share a screenshot and log from the browser console at the moment when redirect to the loopback URI happens? And what version of the plugin are you using?
     
  20. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    In case you've recently updated to the latest version, make sure that you've added 'localhost' to the authorized redirect uris in the google console app settings (it was 127.0.0.1 previously):

     
  21. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    Using latest version with async callback. I have added localhost.

    Here is the only error in log.
     

    Attached Files:

  22. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    Hello Elringus

    It seems the localhost callback does not work on some devices.

    ERR_CONNECTION_REFUSED issue.
     
  23. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    upload_2018-5-26_9-55-21.png

    Screenshot of issue
     
  24. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Well, you can try changing it back to 127.0.0.1 in the GoogleDriveSettings asset (don't forget to whitelist it in the console app).
     
  25. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    I've created a feedback request to add support for nullable types to JsonUtility: https://feedback.unity3d.com/suggestions/add-support-for-nullable-types-to-jsonutility

    Will really appreciate any votes you can spend on this idea :)

     
    Last edited: Jun 3, 2018
  26. psypol

    psypol

    Joined:
    Dec 20, 2013
    Posts:
    25
    hello. just managed to make everything work on android.
    the example scene "FilesList"
    one hurdle was that i could not get the dependencies because of the missing Java_home in variables.

    So now my question :
    Is it possible to just access a shared folder on the drive and not require any loging (auth)
    from user ?

    thanks in advance for any help
     
  27. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    The auth is mandatory to use drive APIs, including anything related to shared resources.
     
  28. psypol

    psypol

    Joined:
    Dec 20, 2013
    Posts:
    25
    thanks for your answer.
    So if i want anyone to be able to log i must share a file with "anyone who has the link" but they must log no matter what.
    is this assumption correct?

    also could you please explain where the texture or file downloaded goes ?
    does it exists in the project somehow or it is just in the memory?
    for example when i download a texture (in demo scene) i see it is applied on the renderer but you cannot track back where this texture "exists" in the project at runtime once it was downloaded.
    same thing for a text file: i manage to get the text via FilesDownloadRange but when i use FilesGet and use a proper file ID i have no idea where the textfile content goes.

    Any clue is welcome !
    regards and congrats for this plugin! can't believe it is opensource
     
  29. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    You'll have to share the resource with specific user account or the user will have to add a publicly-available resource to their drive in order to access it. Though, I'm not 100% sure whether those are the only options, maybe Permissions API (which is not implemented yet) will allow some additional options.

    Well, it goes right where you send it :) When request finishes it's stored in memory, after that you can do anything you want with the data, eg serialize to a local storage or send somewhere else.
     
  30. Flazone

    Flazone

    Joined:
    Jan 25, 2015
    Posts:
    6
    Hi @Elringus, thank you for this amazing tool, it's working very well.

    I'm using your GetFileByPath example but one thing I'm struggling into is getting a file from my Team Drives instead of my regular Drive space.

    I tried to enable both request parameters but it doesn't change anything.

    Here is my code.
    Code (CSharp):
    1.     private IEnumerator GetFileByPathRoutine (string filePath)
    2.     {
    3.         var fileName = filePath.Contains("/") ? filePath.GetAfter("/") : filePath;
    4.         var parentNames = filePath.Contains("/") ? filePath.GetBeforeLast("/").Split('/') : null;
    5.  
    6.         // Resolving folder IDs one by one to find ID of the file's parent folder.
    7.         var parendId = "root"; // 'root' is alias ID for the root folder in Google Drive.
    8.         if (parentNames != null)
    9.         {
    10.             for (int i = 0; i < parentNames.Length; i++)
    11.             {
    12.                 request = new GoogleDriveFiles.ListRequest();
    13.                 request.Fields = new List<string> { "files(id)" };
    14.                 request.Corpora = "teamDrive";
    15.                 request.IncludeTeamDriveItems = true;
    16.                 request.SupportsTeamDrives = true;
    17.                 request.TeamDriveId = "0APEGo8Jgq2HfUk9PVA";
    18.  
    19.                 request.Q = string.Format("'{0}' in parents and name = '{1}' and mimeType = 'application/vnd.google-apps.folder' and trashed = false",
    20.                     parendId, parentNames[i]);
    21.  
    22.                 yield return request.Send();
    23.  
    24.                 if (request.IsError || request.ResponseData.Files == null || request.ResponseData.Files.Count == 0)
    25.                 {
    26.                     result = string.Format("Failed to retrieve '{0}' part of '{1}' file path.", parentNames[i], filePath);
    27.                     yield break;
    28.                 }
    29.  
    30.                 if (request.ResponseData.Files.Count > 1)
    31.                     Debug.LogWarning(string.Format("Multiple '{0}' folders been found.", parentNames[i]));
    32.  
    33.                 parendId = request.ResponseData.Files[0].Id;
    34.             }
    35.         }
    36.  
    Do you know what I'm missing?

    Thanks again!
     
  31. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Well, I haven't actually tested Team Drives myself, so can't tell for sure what is wrong. Can you try using the async helpers? Maybe they will work better.
     
  32. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Also, try using the list request in isolation to list any team drive files to check whether it's working by itself.
     
  33. mattypattyfp

    mattypattyfp

    Joined:
    Feb 13, 2017
    Posts:
    6
    Is it possible to configure this using a google drive API key? If so, is there an example somewhere? I'm wanting to have a WebGL app store files (not user files) on google drive.
     
  34. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Actually, the only way to configure the plugin is to use google drive api app credentials. You can find the setup guide on the GitHub page. Be aware, though, that it's mandatory to complete a per-user authentication to use the Drive.
     
  35. mattypattyfp

    mattypattyfp

    Joined:
    Feb 13, 2017
    Posts:
    6
    Thanks for the quick reply. It seems that all the cloud storage options request per-user authentication. I'm looking for a solution that hearkens back to the good ol' REST API days where you have an API key. I may just have to go that route unless someone knows of a better solution.
     
  36. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Well, GDrive is for private user/team data, no surprise it requires per-user auth. For your case I'd suggest something like this: https://firebase.google.com/products/firestore/
     
  37. mattypattyfp

    mattypattyfp

    Joined:
    Feb 13, 2017
    Posts:
    6
    Thanks, Elringus! I'm building a WebGL app and while they have a Unity SDK for Firebase (which doesn't support web apps), there is no Unity SDK for Firestore (which supports web apps). :-(
     
  38. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    110
    Hi Elringus, I'm searching a plugin to do cloud save game for android, is this project can do this? I see it provided very free way to manage file on google drive, very powerful.
    If i use it to do my game's cloud save, any problem? How to do the file conflict if user have multiple saved games on different device? Thank you.
     
  39. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Hi, I guess it should work just ok, but you'll never know until you try :)
     
  40. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    110
    OK i'll give it a try. :) Thanks.
     
  41. TonismoGames

    TonismoGames

    Joined:
    Jun 12, 2018
    Posts:
    111
    Hey,I want to use this package to upload gamesave data. How would I use Googles Appdata for this so players can't tamper with the gamesave?
     
  42. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Hi, Please consult the official API docs on how to use the appdata feature: https://developers.google.com/drive/api/v3/appdata
     
  43. digimbyte

    digimbyte

    Joined:
    Jun 23, 2012
    Posts:
    58
    Hey, I'm looking forward to using this for our project, hope to get it off the ground and working with spreadsheets.
    but i'm having some trouble, since important and completing the setup, I am left with some compile errors that aren't making sense.
    I am using Unity 2018.2.8f1 (64bit)
    Iam wondering if I have a config or network setting that is conflicting.

    Code (CSharp):
    1. UNetWeaver error: Exception :System.InvalidOperationException: Operation is not valid due to the current state of the object.
    2.   at Mono.Cecil.ModuleDefinition.ReadSymbols (Mono.Cecil.Cil.ISymbolReader reader) [0x0002f] in <28cdca1704d2491781795499c297b78b>:0
    3.   at Mono.Cecil.ModuleReader.ReadSymbols (Mono.Cecil.ModuleDefinition module, Mono.Cecil.ReaderParameters parameters) [0x0004a] in <28cdca1704d2491781795499c297b78b>:0
    4.   at Mono.Cecil.ModuleReader.CreateModule (Mono.Cecil.PE.Image image, Mono.Cecil.ReaderParameters parameters) [0x00081] in <28cdca1704d2491781795499c297b78b>:0
    5.   at Mono.Cecil.ModuleDefinition.ReadModule (Mono.Disposable`1[T] stream, System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x0000d] in <28cdca1704d2491781795499c297b78b>:0
    6.   at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x0006c] in <28cdca1704d2491781795499c297b78b>:0
    7.   at Mono.Cecil.AssemblyDefinition.ReadAssembly (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x00000] in <28cdca1704d2491781795499c297b78b>:0
    8.   at Unity.UNetWeaver.Weaver.Weave (System.String assName, System.Collections.Generic.IEnumerable`1[T] dependencies, Mono.Cecil.IAssemblyResolver assemblyResolver, System.String unityEngineDLLPath, System.String unityUNetDLLPath, System.String outputDir) [0x0000f] in C:\buildslave\unity\build\Extensions\Networking\Weaver\UNetWeaver.cs:1763
    9.   at Unity.UNetWeaver.Weaver.WeaveAssemblies (System.Collections.Generic.IEnumerable`1[T] assemblies, System.Collections.Generic.IEnumerable`1[T] dependencies, Mono.Cecil.IAssemblyResolver assemblyResolver, System.String outputDir, System.String unityEngineDLLPath, System.String unityUNetDLLPath) [0x0004c] in C:\buildslave\unity\build\Extensions\Networking\Weaver\UNetWeaver.cs:1888
    10. UnityEngine.Debug:LogError(Object)
    11. Unity.UNetWeaver.Log:Error(String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:20)
    12. Unity.UNetWeaver.Weaver:WeaveAssemblies(IEnumerable`1, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1896)
    13. Unity.UNetWeaver.Program:Process(String, String, String, String[], String[], IAssemblyResolver, Action`1, Action`1) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:34)
    14. UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)
    15.  
    and
    Code (CSharp):
    1. Failure generating network code.
    2. UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)
    3.  
     
  44. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Hi, I can't see any references to the UnityGoogleDrive plugin in the logs you've shared. The issue is probably with something else.
     
  45. digimbyte

    digimbyte

    Joined:
    Jun 23, 2012
    Posts:
    58
    Never mind, I think when I renamed something it screwed up my entire unity project.
    I'm glad I have been able to find the forums to discuss the SDK however.
    I'm not the best C# coder by far, but I was wondering if I could get some advice on how I would want to search a directory and find a google spreadsheet and read its table data?
     
  46. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Here is a high-level info on the matter: https://github.com/Elringus/UnityGoogleDrive#how-to-access-a-file-using-its-path And you can find more info in the drive API docs.
     
  47. digimbyte

    digimbyte

    Joined:
    Jun 23, 2012
    Posts:
    58
    Thanks for the link, I've got it working but I have one question, I'd like for it to use my apps drive, not the users Google Drive but it doesn't like the Service Account's Json generated, nor does it seem to support this in the Google Drive Settings.
    Suggestions?
     
    Last edited: Nov 1, 2018
  48. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Well, if you'd like it to use your apps drive, then just use your apps drive credentials when logging in.
     
  49. digimbyte

    digimbyte

    Joined:
    Jun 23, 2012
    Posts:
    58
    I am confused, would I make a call with the helper or tweak some settings in Google Drive Settings?
    I changed the Client_id and other settings to match the App auth token but when I loaded the project onto a second machine, it still asked for authorization on a second machine.

    Edit: Reading through the forum, I saw mention of Firebase and other cloud-based storage implementation, so I might have to drop it as I can't give out the app login credentials to anyone, team or not.
     
  50. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    I guess you're trying to use Google Drive as a replacement for a database, but it's not intended to be used like that. Auth is mandatory when user is accessing a drive account for the first time.