Search Unity

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

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

  1. janssonjr

    janssonjr

    Joined:
    Nov 15, 2015
    Posts:
    4
    I get "Unable to complete SSL connection" error when trying to download an image. Do you have any idea why that is? Do you know what it means? It is always different images that gets the error
     
  2. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Try googling it, there are a lot of threads regarding this issue. It's related with Unity's networking layer, nothing I can fix myself, unfortunately.
     
  3. janssonjr

    janssonjr

    Joined:
    Nov 15, 2015
    Posts:
    4
    Thanks for your reply. I think I have figured out the problem, which was that I sent too many request to google under a short period of time. Is there a way of downloading multiple files at once? or downloading a folder?
     
  4. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    I think there is a limit of 2 or 3 concurrent requests to the API, though I wasn't able to find any solid info on this.
     
  5. Bodix_

    Bodix_

    Joined:
    May 6, 2018
    Posts:
    15
    Hi! I am developer of app which using UnityGoogleDrive. Its working in Editor and iOS. But on Android platform after choosing account for Google Drive its not ask me for giving permissions and not redirect to my response page with "Please, return to the app" text for some reason. Instead of this it waiting 10-20 seconds and redirect to google.com. File not uploading on Android.

    I guess it associated with threading on Android. I think something happening with HttpListener, which started and callback doesn't sends in other thread. Maybe not.

    Can you suggest me a solution, please? Thank you.
     
  6. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Hi, Looks like this is connected with the redirection issue: https://github.com/Elringus/UnityGoogleDrive/issues/33
    Unfortunately, I currently don't have time to to properly check it out. I'll update the issue on GitHub when something will change.
     
  7. janssonjr

    janssonjr

    Joined:
    Nov 15, 2015
    Posts:
    4
    Hi!

    I have problem with updating an existing file. I just want to change the description of the file. Is that possible? The error I get is: "
    UnityGoogleDrive: Generic/unknown HTTP error
    Google Drive API Error Description: Code '403' Message: 'The resource body includes fields which are not directly writable.'
    - Domain: 'global' Reason: 'fieldNotWritable' Message: 'The resource body includes fields which are not directly writable.' LocationType: '' Location: '' ".

    I can't find any information that helps me.

    Code (CSharp):
    1.  
    2.     private void Start()
    3.     {
    4.         var req = GoogleDriveFiles.Get("id");
    5.         req.Fields = new List<string> { "*"};
    6.         req.Send().OnDone += MainPanel_OnDone;
    7.     }
    8.  
    9.  
    10.     private void MainPanel_OnDone(UnityGoogleDrive.Data.File obj)
    11.     {
    12.         obj.Description = "This is a new description";
    13.         var req = GoogleDriveFiles.Update(obj.Id, obj, "image/png");
    14.         req.Send().OnDone += onDoneUpdate;
    15.     }
    16.  
    17.     private void onDoneUpdate(UnityGoogleDrive.Data.File obj)
    18.     {
    19.         Debug.Log("UpdateDone!");
    20.     }
    Am I missing something?
     
  8. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Hi, In case you know ID of the file you can update its metadata in a single update request. Take a look at the automated tests on GitHub for an example.
     
    janssonjr likes this.
  9. janssonjr

    janssonjr

    Joined:
    Nov 15, 2015
    Posts:
    4
    Didn't see those files. It worked! Thank you so much! :D
     
  10. Tenebris_Lab

    Tenebris_Lab

    Joined:
    May 23, 2017
    Posts:
    35
    Hello @Elringus I am having an error on android devices. Auth screen does not pop up?

    Code (CSharp):
    1. 12-24 08:37:03.797 21956 21975 E Unity   :   at UnityEngine._AndroidJNIHelper.GetMethodID (System.IntPtr jclass, System.String methodName, System.String signature, System.Boolean isStatic) [0x0
    2. 12-24 08:37:03.949 21956 21975 E Unity   : AndroidJavaException: java.lang.NoSuchMethodError: no static method with name='SetResponseListener' signature='(Lcom.elringus.unitygoogledriveandroid.AuthorizationActivity$OnAuthorizationResponseListener;)V' in class Lcom.elringus.unitygoogledriveandroid.AuthorizationActivity;
    3. 12-24 08:37:03.949 21956 21975 E Unity   : java.lang.NoSuchMethodError: no static method with name='SetResponseListener' signature='(Lcom.elringus.unitygoogledriveandroid.AuthorizationActivity$OnAuthorizationResponseListener;)V' in class Lcom.elringus.unitygoogledriveandroid.AuthorizationActivity;
    The Above is the error log when debugging the android device. Any ideas.
     
  11. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Hello, Thanks for the report! Looks like the same issue is currently open on GitHub: https://github.com/Elringus/UnityGoogleDrive/issues/34 I guess it would be more convenient to move the discussion there.
     
  12. DreamingInsanity

    DreamingInsanity

    Joined:
    Nov 5, 2017
    Posts:
    101
    Hello @Elringus,

    I am having a problem getting the file count in my drive.
    I tried using the:
    Code (CSharp):
    1. GoogleDriveFiles.List().Send().OnDone += fileList;
    But when I print it:
    Code (CSharp):
    1. print(fileList);
    I just get 'null'. How do I get a number of how many files there is?

    This is an amazing asset! I'm suprised it's free!
    Thanks,
    Dream
     
  13. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Well, you're printing reference to a delegate (presumably) and it appears to be null. Please consult google drive api docs for the usage examples.
     
  14. DreamingInsanity

    DreamingInsanity

    Joined:
    Nov 5, 2017
    Posts:
    101
    I am really sorry for bothering you but I just can't seem to get it to work.
    I ahve read through the documentation, tried many of my own ways and I either just get 'null' or an error (or nothing).

    How shall I go about doing it?

    Dream.
     
  15. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    You have to either add a listener, use async await or unity coroutines to access the response object; there you can find the requested info (eg, files list). Though counting the files could require sending multiple list requests in case they don't fit the list limit. Here you can find an example on how to use the list request: https://github.com/Elringus/UnityGoogleDrive/blob/master/Assets/Scripts/TestFilesList.cs#L51
     
  16. DreamingInsanity

    DreamingInsanity

    Joined:
    Nov 5, 2017
    Posts:
    101
    Thank you so much for the link, it was very helpful.

    With a few modifications I got it to work!

    Thanks again,
    Dream.
     
  17. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    Working here it's amazing maybie need little help
    so we got list need name of file and share link
    thank's
     
  18. Taehun12

    Taehun12

    Joined:
    Oct 30, 2018
    Posts:
    2
    Thank you for awesome sdk!

    I have a question. I want that our apps user do not login google drive and don't see authentication page.

    Our game need storage only store some pictures and text files and this files are using common to every users.

    So I found two ways. One is using playground(?) and the other is using service account.

    I failed both two ways.

    Using playground is so difficult...

    And using the service account, we succeeded in getting tokens by referring to the following link.
    http://leoncvlt.com/blog/json-web-token-jwt-for-google-cloud-platform-in-unity/

    After then what should I do with the api to get the file I want?

    If I use JWT, what work should I skip and what work should I add?
     
  19. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Just as mentioned in the FAQ, that is not possible. Auth is mandatory.
     
  20. Lichter

    Lichter

    Joined:
    Mar 5, 2014
    Posts:
    9
    @Elringus Thank you for your awesome work on this project! I have been bashing my head against the wall trying to make the various offerings from Google work properly on my NVIDIA Shield TV. Google's documentation has me going in circles. Your project was and continues to be the only thing that has truly worked. Thanks for the clear instructions on the project's README!

    My big stumbling block to date has been the sign-in/authorization step on Android, and this is what UnityGoogleDrive seems to master. Google's offerings have all failed me on Android:
    There are any number of reasons I couldn't get these to work on Android, but that is not the point of my post.

    Instead I want to ask you some architectural questions. I need to decide on a Google Drive API for a long-term project, and need to justify the decision to my team. My choices are to use UnityGoogleDrive, keep bashing away on Google's official options, or both. So in no particular order:
    1. Comparing UnityGoogleDrive to the official Google Drive API for .NET. The public interfaces are very similar, yet the implementations are completely independent. Can you explain why you couldn't (or chose not to) use the official Nuget API?
    2. Would it be possible for me to mix and match UnityGoogleDrive with Google's official APIs on Nuget? For example, use UnityGoogleDrive for sign-in/authorization, and use the Nuget packages for Drive or YouTube access?
    3. Likewise would it be possible for me to mix and match UnityGoogleDrive with Google's official Firebase SDK? For example, use UnityGoogleDrive for sign-in/authorization and Drive support, and use Firebase SDK for Analytics and Realtime Database?
    Basically, I need to understand how UnityGoogleDrive might facilitate or inhibit our ability to use other Google services in the future.

    Thanks!
     
  21. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Hi, I'm glad you found the project useful! Regarding the questions:
    1. When I decided to start working on the project, Unity didn't support modern .NET so it was impossible to use the official SDK. That was the main reason. Another thing is the cross-platform auth; I'm not 100% sure, but I think the official .NET SDK doesn't provide native auth for android, iOS and WebGL (they all use different schemes).
    2. If you need just the auth, I would suggest to continue trying with the official google's sign-in plugin. It should be much more reliable and supported; it's Google after all :)
    3. Can't really say anything regarding the mixing with the firebase or nuget sdks, as I didn't ever use them. Theoretically it should be possible, if you'll be able to extract the auth tokens from my solution and pass them to others.
     
    Lichter likes this.
  22. Lichter

    Lichter

    Joined:
    Mar 5, 2014
    Posts:
    9
    Thanks for the super fast reply!

    You are correct (at least with Android, all that I tried). The official SDK was using `System.Diagnostics.Process.Start` to launch a web browser :) Looks like it's for desktop only.

    Hah, you'd think! No, you're putting Google to shame in that department! :)

    Thanks for the helpful info!
     
    Elringus likes this.
  23. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    One more idea: in case you're targeting only the Android platform and the project is a long-term one, you could be better of with a custom "in-house" solution based on an open-source native auth lib (such as https://github.com/openid/AppAuth-Android, which I've used in the project).
     
  24. Lichter

    Lichter

    Joined:
    Mar 5, 2014
    Posts:
    9
    The thought had crossed my mind. We'll probably target more than Android (and least Windows Editor) but in the long term we may pursue that if the need arises. I think your current solution of launching a browser is more than sufficient for the time being. Thanks!
     
  25. Lichter

    Lichter

    Joined:
    Mar 5, 2014
    Posts:
    9
    Hey @Elringus, one more question. I notice that UnityGoogleDrive works with older versions of Unity like 2017.4. That surprises me a little bit, because when I was trying the official Google APIs, I was unable to connect to Google authorization servers with anything less than Unity 2018.2. That's because up until that point, Unity did not support the TLS 1.2 protocol (search "unity TLS 1.2" if you're unfamiliar with the issue).

    Did you run into the TLS 1.2 issue while you were developing UnityGoogleDrive? If so, how did you address it?
     
  26. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    I was using Unity's web API (not the .NET one), which always supported the stuff, so didn't had any such issues.
     
    Lichter likes this.
  27. SystemDevel

    SystemDevel

    Joined:
    Oct 5, 2013
    Posts:
    36
    Hi @Elringus , There is any solution to share with all permission an uploaded file? I can't find how to do this.
    Thanks you
     
  28. SystemDevel

    SystemDevel

    Joined:
    Oct 5, 2013
    Posts:
    36
    Hi @psypol do you find the solution to your problem? I'm on same issue.

    Thanks you
     
  29. Bazookas

    Bazookas

    Joined:
    Jul 29, 2013
    Posts:
    7
    Hello @Elringus

    I got the plugin working and I am able to list the available documents after the user has logged in both in editor and on an Android smartphone. But I wanted to use the plugin on an Oculus Quest. I thought this wouldn't be a problem since Android is supported and works, but it does not work. The Quest Browser is opened and the user is asked to log in. This works, but the browser does not close or redirect back to the game. Manually going back to the game does not seem to work as the callback listing all available documents is not executed. I was wondering if you have any insight in what the problem could be.

    Kind regards,
    Tim

    UPDATE: using the Android Device Monitor I saw that an Exception is thrown: Exception: No such proxy method: UnityGoogleDrive.AndroidAccessTokenProvider+OnAuthhorizationResponseListener.onAuthorizationResponse(System.Boolean, UnityEngine.AndroidJavaObject, System.String, System.String, System.String)
     
    Last edited: Jul 25, 2019
    Jerrymev11 likes this.
  30. HeladioMoralesDorantes

    HeladioMoralesDorantes

    Joined:
    Mar 2, 2019
    Posts:
    3
    Hi! Sorry this is probably a noob mistake but I get this error, I have already tried to reimport the project, change the references directly from the solution in Visual Studio, re-import the package, etc... Could you help me? Sorry and Thanks!

    upload_2019-9-2_17-36-33.png
     
  31. Jerrymev11

    Jerrymev11

    Joined:
    Mar 1, 2017
    Posts:
    9
    @Bazookas Did you figure it out? I ran into the same issue today and am wondering how to work around it
     
    Last edited: Sep 6, 2019
  32. G-Reusch

    G-Reusch

    Joined:
    Sep 28, 2013
    Posts:
    5
    I've been meddling with Google's .NET API for a few days now and have been fighting a lot of errors. Finding this plugin might be just what I need.

    I have some questions about authentication though. I do indeed fall into the camp of "using Drive like a database", but all of my research seems to suggest that you can use a service account to access shared Drives without user login. I haven't been able to get it to work myself, but it seems like you can manually share the Drive folder(s) with the generated email and use some JSONs with credentials. Am I misunderstanding how that works or is there some other reason this package can't use a similar setup?

    Ultimately I could still use this, have my users log in, then just handle any extra logic/permissions app side (asinine as it would be to use Google login for nothing but authentication). If this ends up being the route I take, I'd just have to manually share the folder with their accounts and they'd be prompted for auth when they boot the app the first time? I can obviously restrict the app to stay within the folder I shared, but I want to make sure this isn't something where the users have to authorize constantly or I have to keep sharing/sending them things.

    Thanks
     
  33. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Even if it's somehow possible (which I doubt), such shared usage would probably violate the TOS, so I'd advise against spending time on that hack and choose a more appropriate tool for the job instead.
     
  34. G-Reusch

    G-Reusch

    Joined:
    Sep 28, 2013
    Posts:
    5
    I mean, it's literally just allowing my app to access stuff that I have in a shared folder. There's no need to access any user's files except my own. I can functionally do the same thing by making the folder public or just sharing it manually, though neither of those give me any additional functionally. Furthermore it's a personal app for a few close friends, so idk how that would violate anyone's ToS.

    Regardless, does your solution require multiple logins or is it a one and done thing? I know there are refresh tokens involved but I want to make sure that actual authorization screen is only popping up once when they load the app the first time. As far as functionality I can just limit all of my queries to the single shared folder by ID and manually add each user to the shared folder.
     
  35. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Ah, if it's for a limited number of users, then it could work. Though, I still don't see a reason to build a hacks like that, when you could choose a proper database service, which also has free tiers (fauna db, for example).
     
  36. G-Reusch

    G-Reusch

    Joined:
    Sep 28, 2013
    Posts:
    5
    It's largely an image and video service (with lots of metadata for searching and such), so just a database is a bit too limited for me. Originally I was going to do Google Cloud since it can do databases, file storage, and lots of other stuff like AI/ML, but those libraries also had some compatibility issues with Unity's .NET changes. Weird as it may seem, Google Drive is actually the cleanest and easiest solution for me, bar this authentication stuff. It also helps that our existing images/videos are in Drive, which saves me a lot of porting time.

    I would definitely like to try to use your solution and have my users login, but I don't want to spend lots of time implementing it if they have to log in constantly. Do the refresh tokens prevent this?

    Thanks for the dialog and quick responses btw. Google's support for this kind of stuff is non-existent so it's nice to find people that can actually help.
     
  37. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    I see. The refresh tokens indeed allow to skip the repeated auth when accessing from the same device. Can't remember the exact expiration time though, it should be around month or so. The only exception are the webgl builds, tokens expire in like one hour there due to some security restrictions.
     
    G-Reusch likes this.
  38. Jerrymev11

    Jerrymev11

    Joined:
    Mar 1, 2017
    Posts:
    9
    hey @Elringus any idea what might be done to fix this issue?
    an Exception is thrown: Exception: No such proxy method: UnityGoogleDrive.AndroidAccessTokenProvider+OnAuthhorizationResponseListener.onAuthorizationResponse(System.Boolean, UnityEngine.AndroidJavaObject, System.String, System.String, System.String)
     
  39. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Which one?
     
  40. Jerrymev11

    Jerrymev11

    Joined:
    Mar 1, 2017
    Posts:
    9
    an Exception is thrown: Exception: No such proxy method: UnityGoogleDrive.AndroidAccessTokenProvider+OnAuthhorizationResponseListener.onAuthorizationResponse(System.Boolean, UnityEngine.AndroidJavaObject, System.String, System.String, System.String)
    So every time i try running my test application, it sends me to a google requests page, and i click on accept or deny, and i get that exception on adb.
     
  41. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Try disabling the managed stripping (if building under mono) or use the "low" profile when under il2cpp.
     
  42. Jerrymev11

    Jerrymev11

    Joined:
    Mar 1, 2017
    Posts:
    9
    It is on low or il2cpp.
    I'll try building it with mono and disabled stripping
     
  43. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Also, try updating the native dependencies (check which appauth version is currently the last one and edit the dependency manifest file in the package, then force-resolve with the playservices tool).
     
    Jerrymev11 likes this.
  44. Jerrymev11

    Jerrymev11

    Joined:
    Mar 1, 2017
    Posts:
    9
    do i update the appauth to 9.0 ?
    upload_2019-9-10_22-44-11.png
     
  45. Jerrymev11

    Jerrymev11

    Joined:
    Mar 1, 2017
    Posts:
    9
    So i updated the appauth version in the dependency manifest to 0.7.1 and force resolved for android. I still get the error.
     
  46. greay

    greay

    Joined:
    Mar 23, 2011
    Posts:
    88
    I'm running into this as well, and upping the version for appauth to the latest I can find (0.7.1) didn't seem to change anything for me, either.

    Authorization seems to work fine; I can log in and everything works pretty much as expected from the user's point of view. But I can't catch errors or cancelling out of the login process.

    I'm currently building with mono. Managed stripping is already disabled.
     
  47. greay

    greay

    Joined:
    Mar 23, 2011
    Posts:
    88
    after looking closer at that method signature, this worked for me (in AndroidAccessTokenProvider.cs):

    Code (CSharp):
    1. private void onAuthorizationResponse (bool isError, UnityEngine.AndroidJavaObject error, string codeVerifier, string redirectUri, string authorizationCode)
    2. {
    3.     var response = new AuthorizationResponse {
    4.         IsError = isError,
    5.         Error = (error != null ? error.ToString() : null),
    6.         CodeVerifier = codeVerifier,
    7.         RedirectUri = redirectUri,
    8.         AuthorizationCode = authorizationCode
    9.     };
    10.  
    11.     if (OnAuthResponse != null)
    12.         OnAuthResponse.Invoke(response);
    13. }
     
    Jerrymev11 likes this.
  48. thao050192

    thao050192

    Joined:
    Jul 17, 2017
    Posts:
    5
    my window can't show "manage google drive api app"
     

    Attached Files:

  49. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    Thank you for sharing this! I've published a new release where the auth cancellations on Android are now properly handled.
     
    Jerrymev11 and greay like this.
  50. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    483
    That's because you didn't setup the app yet. Use 'create google app' first and parse the credentials.
     
    thao050192 likes this.