I am aware that this is going to be a very specific issue, but here goes.
I’m working on a package that makes authorization and use of the Google Sheets API from Unity much easier, but once my application is built to an iOS device the OAuth 2.0 authorization stops working entirely. A quick break down of the OAuth 2.0 system it uses:
In order to perform both read and write requests from a Google spreadsheet, you must use OAuth 2.0 authorization. This requires you to assign an OAuth 2.0 credential on the Google Cloud Dashboard for your project, which gives you a .json file (or a .plist file for an iOS device) that contains the client secret information. It’s basically a set of special passwords to grant you permission to obtain an access token from Google, which lets you interact with the Google Sheets API as normal. The following code is what I have been using, and has been working fine up until now:
UserCredential credential;
string fileName = "credentials.json";
// load client secrets
using (var stream = new FileStream(Path.Combine(Application.streamingAssetsPath, fileName), FileMode.Open, FileAccess.Read))
{
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.FromStream(stream).Secrets, scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result;
// create Google Sheets API service
service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = applicationName
});
}
What this does is load the credentials file, obtain its client secrets information, and send it to Google to get the access token (called credential here). Using this token, it then starts a live service connected to a Google spreadsheet.
This process works well on desktop (and took a lot of headache to get working), but once built into an iOS device it stops working. Nothing I have tried has worked, it’s able to see the credentials file (I change fileName to reference the correct .plist file when building), but it seemingly can’t read it in .plist format, throwing a “Could not parse ‘<’” error. Converting the .plist to a .json lets it read it, but it seems to confuse the GoogleWebAuthorizationBroker and interpret it as a regular desktop credential, which doesn’t work either.
I’ve also tried simply entering the client secrets information directly as a ClientSecrets class, which works perfectly fine on desktop, but I seemingly can’t find a way to get it to function on iOS. It just keeps saying that I have no authorization to do that action, so I’m assuming it’s referring to the credentials not being set up correctly.
If there is anyone on this forum who has tackled the beast that is the Google Sheets API before, please help! There is so little information out there on the Google Sheets or Authorization APIs, let alone specifically for Unity. Practically none exists for iOS Unity apps using Google Sheets either. I’m completely stumped.