Completely new to Google SpreadSheet API (v4). I am using .Net (5.0) to create a new spreadsheet, which I assumed would be saved in my Google Drive / account.
Cobbled together the following from what examples / docs I could find, but I do not understand where the spreadsheet is being saved (stored) - as I cannot locate it within my account.
Below is the code I am using -- which executes without error and returns a spreadsheet ID and URL -- but the spreadsheet is nowhere to be found in my Google account !!
String sheet_name;
Google.Apis.Sheets.v4.SpreadsheetsResource.CreateRequest create_request;
Google.Apis.Sheets.v4.Data.Spreadsheet spreadsheet_body;
Google.Apis.Sheets.v4.Data.Spreadsheet spreadsheet;
Google.Apis.Sheets.v4.Data.Sheet sheet;
// Create spreadsheet object and set properties ...
spreadsheet_body = new Google.Apis.Sheets.v4.Data.Spreadsheet();
spreadsheet_body.Properties = new Google.Apis.Sheets.v4.Data.SpreadsheetProperties();
spreadsheet_body.Properties.Title = "TEST1";
// Create list of sheets to include in this spreadsheet ...
spreadsheet_body.Sheets = new List<Google.Apis.Sheets.v4.Data.Sheet>();
// Create a sheet object and set properties ...
sheet_name = "Sheet 1";
sheet = new Google.Apis.Sheets.v4.Data.Sheet();
sheet.Properties = new Google.Apis.Sheets.v4.Data.SheetProperties();
sheet.Properties.Title = sheet_name;
sheet.Properties.SheetId = 1;
sheet.Properties.SheetType = "GRID";
// Add sheet to this spreadsheet ...
spreadsheet_body.Sheets.Add( sheet );
// Try to create the spreadsheet ...
try
{
create_request = sheet_service.Spreadsheets.Create( spreadsheet_body );
spreadsheet = create_request.Execute();
// Spreadsheet ID returned -- but where is the spreadsheet saved??? ...
Console.WriteLine( $"spreadsheet.SpreadsheetId: {spreadsheet.SpreadsheetId}" );
Console.WriteLine( $"spreadsheet.SpreadsheetUrl: {spreadsheet.SpreadsheetUrl}" );
}
catch ( Exception ex )
{
Console.WriteLine( ex.ToString() );
}
}
When I cut and paste the returned URL into a browser -- Google displays the following:
You need access Ask for access, or switch to an account with access.
... with a button entitled "Request Access" -- when clicked on, the system displays:
Request sent You'll get an email letting you know if the file is shared with you
... but I never receive any email
I am using a service account / credentials when making the requests to the API, could this be the problem?
If anyone has a working example of creating a Google spreadsheet within their own Google account via the API, please share.
Any help / insights would be very much appreciated.