Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question Google Sheets & OAuth

Discussion in 'Editor & General Support' started by daveMennenoh, Feb 6, 2023.

  1. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    59
    HI there, I need to be able to allow users to paste in a google sheets URL in my app, and then read data from it. I can see the data if I make the sheet not-private, and use an API key. However, I also need to be able to read private sheets and write data back to them. Which means I have to use OAuth2.
    Looking for some examples or good documentation. All the tutorials on YT for Unity and Sheets all use the API Key... because it's easy.
    Any help much appreciated.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    32,284
    There's a fair number of Oauth2 packages on the Unity Asset Store. I haven't used any of them myself, not even sure if any of them are useful, but at least that's a thing to look at.
     
  3. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    59
    Thanks but not what I'm looking for.
     
  4. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    59
    Hi there. So I did find a package on GitHub that includes Google Sheets. So have been trying to implement but the documentation is non-existent so not having a lot of luck.
    Here's the package on Git:
    https://github.com/cdmvision/authentication-unity

    Code (CSharp):
    1. private void Start()
    2.     {
    3.         AuthorizationCodeFlow.Configuration config = new AuthorizationCodeFlow.Configuration();
    4.         config.clientId = "...";
    5.         config.clientSecret = "...";
    6.         config.redirectUri = "/";
    7.  
    8.         var auth = new GoogleAuth(config);
    9.         testIt(auth);
    10.     }
    11.  
    12.     private async void testIt(GoogleAuth auth)
    13.     {
    14.         var authenticationSession = new AuthenticationSession(auth, new StandaloneBrowser());
    15.         AccessTokenResponse accessTokenResponse = await authenticationSession.AuthenticateAsync();
    16.     }
    And now in Console I get:
    Making authorization request...
    Getting authorization grant using browser login...

    But then:
    ArgumentNullException: Value cannot be null.
    Parameter name: uriPrefix

    So it wants a redirect URI. But I have no clue how to provide one. I've heard of this 'deep linking' method but not sure how to do it and my app is already open.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    32,284
    Doesn't that come back in the response when you get a browser challenge??