-
Notifications
You must be signed in to change notification settings - Fork 7
7.2 Protected Google Sheets
Jos de Weger edited this page Jan 1, 2019
·
2 revisions
Getting the data for a protected document requires the use of the ProtectedGoogleSheetAdapter
. This adapter has one method for getting data: Task<Sheet> GetAsync(string authenticationJsonFilePath, string documentName, string sheetId, string range)
.
Parameters explained:
-
authenticationJsonFilePath
: json file containing auth details, see Enable Security for the Google Sheet below -
documentName
: the name of the Google Sheets document -
sheetId
: the id of the sheet, which you can find in the url when viewing the sheet on Google Sheets -
range
: for example 'my sheet'!A1:E4
Example:
var adapter = new ProtectedGoogleSheetAdapter();
var sheetData = await adapter.GetAsync("secret.json", "My Document", "my-sheet-id", "A1:E4");
var result = sheetMapper.Map<MyModel>(sheetData);
The steps to create a protected sheet:
-
Create a Google Sheet
-
Enable the Google Sheets Api in the developers console
- Download a json file with the credentials
- Add the json file to your project and make sure to set the "Copy to output directory" to "Copy Allways":
- Add the email address from the secret.json to the Google Sheets document