Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Frostoise · Oct 09, 2020 at 01:06 PM · wwwgoogleexception

GoogleApiException: Parameter "spreadsheetId" is missing

Hey everyone, I'm trying to access Google Spreadsheets API in my app. But i have ran into a problem on the il2cpp Android build of my app.

 using System.Collections.Generic;
 using UnityEngine;
 
 using Google.Apis.Auth.OAuth2;
 using Google.Apis.Sheets.v4;
 using Google.Apis.Services;
 using Google.Apis.Sheets.v4.Data;
 using System.Security.Cryptography.X509Certificates;
 
 using System.Text;
 using TMPro;
 public class GoogleSheetsTest : MonoBehaviour
 {
 
     public TextMeshProUGUI text;
 
     string p12PathFromAsset;
 
     
     const string sheetNameAndRange = "A!A1:D13";
     const string serviceAccountEmail = "MY_SERVICE_ACCOUNT";
     static SheetsService service;
 
     private void Awake()
     {
         RequestPath();
     }
 
     void RequestPath()
     {
         string keyPath = "P12_KEY_LOCATION";
         string realPath;
 
         if (Application.platform == RuntimePlatform.Android)
         {
             // Android
             string oriPath = System.IO.Path.Combine(Application.streamingAssetsPath, keyPath);
 
             // Android only use WWW to read file
             WWW reader = new WWW(oriPath);
             while (!reader.isDone) { }
 
             realPath = Application.persistentDataPath + "P12_KEY_STUFF";
             System.IO.File.WriteAllBytes(realPath, reader.bytes);
 
             Debug.Log("Running Android");
 
             p12PathFromAsset = realPath.Replace("p12",".p12");
         }
         else
         {
             // iOS
             p12PathFromAsset = System.IO.Path.Combine(Application.streamingAssetsPath, keyPath);
         }
 
         SyncData();
 
     }
 
     void SyncData()
     {
 
         var certificate = new X509Certificate2(p12PathFromAsset, "notasecret", X509KeyStorageFlags.Exportable);
 
         text.text = p12PathFromAsset;
 
         ServiceAccountCredential credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                Scopes = new[] { SheetsService.Scope.Spreadsheets }
                /*
                 Without this scope, it will :
                 GoogleApiException: Google.Apis.Requests.RequestError
                 Request had invalid authentication credentials. Expected OAuth 
                 2 access token, login cookie or other valid authentication 
                 credential.
                 lol..
                 */
            }.FromCertificate(certificate));
 
         service = new SheetsService(new BaseClientService.Initializer()
         {
             HttpClientInitializer = credential,
         });
 
         string spreadsheetid = "MY_SPREADSHEET_ID";
         var request = service.Spreadsheets.Values.Get(spreadsheetid, sheetNameAndRange);
 
         StringBuilder sb = new StringBuilder();
 
         ValueRange response = request.Execute();
         IList<IList<object>> values = response.Values;
         if (values != null && values.Count > 0)
         {
             foreach (IList<object> row in values)
             {
                 foreach (object cell in row)
                 {
                     sb.Append(cell.ToString() + " ");
                 }
 
                 //Concat the whole row
                 Debug.Log(sb.ToString());
                 text.text = sb.ToString();
 
                 sb.Clear();
             }
         }
         else
         {
             Debug.Log("No data found.");
         }
     }
 }    

It's a simple script that gets the Google Sheet with the "MY_SPREADSHEET_ID", then authorises my access via "MY_SERVICE_ACCOUNT" , with the p12 key linked to the service account. The script has no problems, running on Editor. On Android i can access the p12 path and i dont think i have auth issues. But when i run it i get this exception on Android Logcat:

alt text

I have no idea what could be causing this exception since it can perfectly read and get data from the spreadsheet on Editor. I tried a const string variable, getting rid of the variable and just typing the string to the method field. I tried to search online but it seems nobody has this problem but me.

Thanks in advance.

googleexception.png (37.0 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Frostoise · Oct 09, 2020 at 01:07 PM 0
Share

The same issue happens on the $$anonymous$$ono build as well.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Frostoise · Oct 12, 2020 at 06:17 PM

Alright so, Google Sheets is not officially supported for Unity. You can force it with NuGetforUnity, and it works for mono pc builds, but i guess android port with il2ccp makes it not work.

If anyone encounters the same problem, i recommend using Google Firebase for data transfer, instead. It is fully supported for Unity and so far worked perfectly with all my builds.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by FrostweepGames · Feb 14 at 08:18 AM

Hello,

the fix is to add a link.xml file with these content:

 <linker>
     <!-- Preserve types and members in an assembly -->
     <assembly fullname="Google.Apis.Auth" preserve="all" />
     <assembly fullname="Google.Apis.Auth.OAuth2" preserve="all" />
     <assembly fullname="Google.Apis.Auth.PlatformServices" preserve="all" />
     <assembly fullname="Google.Apis.Sheets.v4" preserve="all" />
     <assembly fullname="Google.Apis.Core" preserve="all" />
     <assembly fullname="Google.Apis" preserve="all" />
     <assembly fullname="Google.Apis.PlatformServices" preserve="all" />
     <assembly fullname="Newtonsoft.Json" preserve="all" />
 
 </linker>

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

144 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

embed google maps into unity 3d 4 Answers

WWW Request for image error, unsupported URL 1 Answer

Android https request returns SSLHandshakeException 2 Answers

Exception: not implemented? 2 Answers

How to write a HTTPS Post Request 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges