Google API - 使用 API 密钥而不是 OAuth2 从 google 表中读取
Google API - Read from google sheets using API key, not OAuth2
我正在尝试将一个项目从 Java 转移到 c#。该项目使用 Google Sheets API 密钥,而不是 OAuth2
Google 网站上的文档仅显示了如何为 OAuth2 执行此操作 - https://developers.google.com/sheets/api/quickstart/dotnet#step_2_set_up_the_sample
原Java代码为
Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, httpRequestInitializer)
.setApplicationName(APPLICATION_NAME)
.build();
Spreadsheet sp = service.spreadsheets().get(spreadsheetId).execute();
List<com.google.api.services.sheets.v4.model.Sheet> sheets = sp.getSheets();
我正在努力转换为 C#。我试过了
static string ApplicationName = "@Timetable";
private static readonly String API_KEY = "APIKEY";
static readonly string spreadsheetId = "SPREADSHEET ID";
public void getSheets() {
var service = new SheetsService(new BaseClientService.Initializer()
{
ApplicationName = ApplicationName,
ApiKey = API_KEY,
});
var ssRequest = service.Spreadsheets.Get(spreadsheetId);
Spreadsheet ss = ssRequest.Execute();
List<string> sheetList = new List<string>();
}
但我得到错误
System.ArgumentException: 'Invalid Application name Arg_ParamName_Name'
正确的流程是什么?
事实证明它不喜欢应用程序名称中的空格或特殊字符
我正在尝试将一个项目从 Java 转移到 c#。该项目使用 Google Sheets API 密钥,而不是 OAuth2
Google 网站上的文档仅显示了如何为 OAuth2 执行此操作 - https://developers.google.com/sheets/api/quickstart/dotnet#step_2_set_up_the_sample
原Java代码为
Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, httpRequestInitializer)
.setApplicationName(APPLICATION_NAME)
.build();
Spreadsheet sp = service.spreadsheets().get(spreadsheetId).execute();
List<com.google.api.services.sheets.v4.model.Sheet> sheets = sp.getSheets();
我正在努力转换为 C#。我试过了
static string ApplicationName = "@Timetable";
private static readonly String API_KEY = "APIKEY";
static readonly string spreadsheetId = "SPREADSHEET ID";
public void getSheets() {
var service = new SheetsService(new BaseClientService.Initializer()
{
ApplicationName = ApplicationName,
ApiKey = API_KEY,
});
var ssRequest = service.Spreadsheets.Get(spreadsheetId);
Spreadsheet ss = ssRequest.Execute();
List<string> sheetList = new List<string>();
}
但我得到错误
System.ArgumentException: 'Invalid Application name Arg_ParamName_Name'
正确的流程是什么?
事实证明它不喜欢应用程序名称中的空格或特殊字符