0

I am using this url:

https://docs.google.com/spreadsheets/u/1/d/e/2PACX-XXXX/pubhtml?gid=XXXX&single=true

I have checked "https://developers.google.com/sheets/api/quickstart/dotnet" but I am not able to find the spreadsheet id using which I can read the data.

I am using .net core 3.1 this is my code:

var credential = GoogleCredential.FromStream(new
    FileStream(_hostEnvironment.ContentRootPath +
       @"/Helper/CLient_secret.json", FileMode.Open)).CreateScoped();
var service = new SheetsService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "",
    });
           
// Define request parameters.  
String spreadsheetId = "XXXX";
String range = "Sheet1!A1:ZZ";//Sheet1 refers to all the cells in Sheet1.
SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadsheetId, range);
           
ValueRange response = request.Execute();
IList<IList<Object>> values = response.Values;

I also have tried other spreadsheets using this code, it reads successfully but the URL pattern was different from above mentioned URL.

For Ex:

https://docs.google.com/spreadsheets/d/ID#edit

I am not sure I am able to explain it properly or not

Palle Due
  • 5,929
  • 4
  • 17
  • 32

3 Answers3

0

The Spreadsheet Id is the value between the "/d/" and the "/edit" in the URL of your spreadsheet

Check the following answer here

Makhele Sabata
  • 582
  • 6
  • 16
0

On the example URL you added, 2PACX-XXXX part would be your spreadsheet ID.

Martí
  • 2,651
  • 1
  • 4
  • 11
0

Finally, I found that this is the published spreadsheets we can not read it using the spreadsheet id.

We have to Ask to creator to share the spreadsheet with us in case if we need the spreadsheets id for google api