1

I'm trying to move a project from Java over to c#. The project uses Google Sheets API key, not OAuth2

The documentation on Google's website show only how to do it for OAuth2 - https://developers.google.com/sheets/api/quickstart/dotnet#step_2_set_up_the_sample

The original Java code is

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();

and i'm struggling to convert to c#. I've tried

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>();
}

but i get the error

System.ArgumentException: 'Invalid Application name Arg_ParamName_Name'

Whats the correct process?

1 Answer 1

1

Turns out it doesn't like spaces or special characters in the application name

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.