Google Drive API library for listing, searching, creating, uploading, editing, copying, downloading, deleting and exporting files on the user’s drive from within Unity game engine.
Works with Unity version 5.6 and higher. Supports all the major platforms: Windows, Mac, Linux, iOS, Android and WebGL.
// Listing files.
GoogleDriveFiles.List().Send().OnDone += fileList => ...;
// Uploading a file.
var file = new UnityGoogleDrive.Data.File() { Name = "Image.png", Content = rawImageData };
GoogleDriveFiles.Create(file).Send();
// Downloading a file.
GoogleDriveFiles.Download(fileId).Send().OnDone += file => ...;
// All the requests are compatible with the .NET 4 asynchronous model.
var aboutData = await GoogleDriveAbout.Get().Send();
Three authentication schemes are used: browser redirection for WebGL builds, custom URI for iOS/Android and local loopback requests for other platforms. All the credentials are stored in a scriptable object; editor script provides shortcuts to create and manage Google Console App, allows to parse credentials JSON to skip manual copy-pasting and edit common settings:
Automated integration tests cover the main features:
The project is open-sourced and I’m planning to support it until Google will make an official Drive API library for Unity or it’ll become possible to use the current official .NET API library in Unity seamlessly on all the platforms.
Taking advantage of this thread, I would like to ask for an advice regarding JSON handling. Currently I’m forced to use a third-party library (Json.Net.Unity3D) to de-/serialize JSON data, as Unity’s built-in one doesn’t suport nullable types (and they’re heavily used in the data API to represent properties not included to a request/response). While the library itself works fine and is .NET 2.0 compatible, the performance is not that good comparing to the native Unity solution and I was really up to making a ‘pure’ solution, without any third-party dependencies. Maybe someone here has an idea how to make nullable types work with the Unity’s JSON tools without complicating code base too much?
You can omit mime type and use any name you like. What really matters is the binary data you’re uploading (‘Content’ property); you’ll have to get the content of the file (as byte array) you wish to upload and use it. If the file is stored locally, you can probably use File.ReadAllBytes method.
Yep, it should work on those platforms. Personally, I’ve only tested it on PC, Android and WebGL, but it should also work on iOS. If you find any issues, please report them here or via GitHub and I’ll take a look.
Hi, I have big trouble to make this working on new iOS devices. I don’t get the access tokens when accepting the browser. I switch back to the app, but nothing happens.
But this only encounters when using wifi. When I disable it and use mobile internet I don’t have these troubles.
Running current Xcode beta 4 and unity 2017.3.1 p3
2018-03-15 22:48:06.105395+0100 artemplategd[1251:354052] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-03-15 22:48:06.107633+0100 artemplategd[1251:354052] [MC] Reading from public effective user settings.
2018-03-15 22:48:12.169209+0100 artemplategd[1251:354244] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
2018-03-15 22:48:12.169375+0100 artemplategd[1251:354244] [BoringSSL] Function boringssl_session_errorlog: line 2881 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
-> applicationWillResignActive()
ar_session_interrupted
UnityEngine.XR.iOS.UnityARSessionNativeInterface:_ar_session_interrupted()
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
-> applicationDidEnterBackground()
2018-03-15 22:48:19.235886+0100 artemplategd[1251:354244] TIC Read Status [4:0x1c0173500]: 1:57
2018-03-15 22:48:19.237008+0100 artemplategd[1251:354244] Task <1D325C96-96E3-49E0-BE05-5B93FA65A352>.<0> HTTP load failed (error code: -1005 [1:57])
2018-03-15 22:48:19.237605+0100 artemplategd[1251:354434] NSURLConnection finished with error - code -1005
-> applicationWillEnterForeground()
2018-03-15 22:48:21.366019+0100 artemplategd[1251:354434] TIC Read Status [5:0x1cc173440]: 1:57
2018-03-15 22:48:21.371482+0100 artemplategd[1251:354434] Task <E63E62CB-1CB6-4B58-B1A7-D5EF94964323>.<0> HTTP load failed (error code: -1005 [4:-4])
2018-03-15 22:48:21.382858+0100 artemplategd[1251:354751] NSURLConnection finished with error - code -1005
Thank you for reporting this! Can you please clarify whether this happens only on specific iOS devices (you’ve mentioned the new ones, but which exactly)?
Yeah, you could try adding those records. The app will definitely need local networking access. Not sure about the NSAppTransportSecurity though. Still, I’m not exactly an expert with those settings
Hmm, if this only happens when connected to a WiFi, I guess there could be something wrong with the router or firewall (on both router or device) config. Not sure what exactly, though. I’ve updated the repo on github, so it should now log the exact error you get from the google auth reponse. Most likely it will be something about the missing token, but still could be helpful.