This document will explain about how to connect to Google Sheet. For general information, see the Repository's README.
To use GoogleSheetConverter
, BakingSheet requires a service account credential and your sheet's identifier.
First, visit Google API Console. Pick API & Services
> Credentials
from sidebar menu.
Create project if you don't have any. Then pick Create Credentials
> Service Account
.
Now fill your preferred service account name for BakingSheet to use. Click Done
(You don't have to fill other options).
You've create service account, now click your new service account and select Keys
tab. Pick Add Key
> Create New Key
.
Select JSON
option to download your key. Save it somewhere under your Assets
folder.
You have Service Account, now create a Google Sheet and Share it to your service account email with Viewer
permission.
From your browser's address bar, you can extract your Google Sheet identifier. The format is like this:
https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit#gid=0
Almost there! Now you can use code below to load your datasheet.
// replace with your Google sheet identifier
string googleSheetId = "1iWMZVI4FgtGbig4EgPIun_BRbzp4ulqRIzINZQl-AFI";
// service account credential than can read the sheet you're converting
// this starts with { "type": "service_account", "project_id": ...
string googleCredential = File.ReadAllText("Some/Path/Credential.json");
var googleConverter = new GoogleSheetConverter(googleSheetId, googleCredential);
// bake sheets from google converter
await sheetContainer.Bake(googleConverter);
Nicely done! 🎉
SheetContainer.Bake
can accept multiple importers. If you want to divide your datasheets into multiple Google Sheet documents, create GoogleSheetImporter
per your document. Code below is the example.
var credential = File.ReadAllText(CredentialPath);
var importers = new List<ISheetImporter>();
foreach (var address in GoogleSheetAddresses)
{
var importer = new GoogleSheetConverter(address, credential, TimeZoneInfo.Utc);
importers.Add(importer);
}
await sheetContainer.Bake(importers.ToArray());
Warning
This is an advanced topic. I recommend you to use this approach Develop environment only, for live-reload without exporting sheet.
By adding BAKINGSHEET_RUNTIME_GOOGLECONVERTER
defining symbol, Google sheet converter will be included on your build.
Additionally for AOT platforms, copy Runtime/Converters/Google/link.xml
under BakingSheet's package into your Assets
directory.