So at the moment I'm simply trying to get a list of all sheet names available in a google sheets. The sheet is a public sheet
The API key and spreadsheet id match what's online, but I'm getting back Error 400, bad request.
class GoogleAPI {
static string ApplicationName = "Timetable";
private static readonly String API_KEY = "AI**D0";
static readonly string spreadsheetId = "1K**h8";
public void getSheets()
{
var sheetsService = new SheetsService(new BaseClientService.Initializer()
{
ApplicationName = ApplicationName,
ApiKey = API_KEY,
HttpClientFactory = new ProxySupportedHttpClientFactory(),
});
SpreadsheetsResource.GetRequest request = sheetsService.Spreadsheets.Get(spreadsheetId);
Data.Spreadsheet response = request.Execute();
Console.WriteLine(JsonConvert.SerializeObject(response));
}
}
The error from the console
Exception thrown: 'Google.GoogleApiException' in System.Private.CoreLib.dll An exception of type 'Google.GoogleApiException' occurred in System.Private.CoreLib.dll but was not handled in user code. The request URL is invalid.
If I echo the details of the request as below
Debug.WriteLine("*********************************");
Debug.WriteLine(sheetsService.BaseUri);
Debug.WriteLine(request.RestPath);
Debug.WriteLine(request.SpreadsheetId);
Debug.WriteLine("***********************************");
I get
https://sheets.googleapis.com/
v4/spreadsheets/{spreadsheetId}
19c3dGbBHhU7EtrCJBa7-bKMn7Jlg3R9xMXOP9HBZDPc
The url giving the correct response is