I’ve created a C# application that uses the .NET API to connect to Google Sheets. So far, it works perfectly for private spreadsheets by using a username and password for authentication. The app combines these credentials with the spreadsheet name and worksheet name to create a DataTable with the data.
My current code looks like this:
SpreadsheetService spreadsheetService = new SpreadsheetService("MyApplication-1");
spreadsheetService.setUserCredentials(userEmail, userPassword);
SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = spreadsheetService.Query(query);
SpreadsheetEntry selectedSpreadsheet = (SpreadsheetEntry)(from entry in feed.Entries
where entry.Title.Text == spreadsheetName
select entry).FirstOrDefault();
Now, I want to modify this to read from public Google Sheets. When a spreadsheet is shared publicly, I receive a link that contains a unique key.
The challenge is that my current method depends on authentication to explore available spreadsheets. For public spreadsheets, I should be able to access them directly without needing to log in if I have the public link.
What is the best method to retrieve a SpreadsheetEntry object from a public Google Sheets URL using the C# API?
I hit this same problem a few months ago switching from authenticated to public sheet access. You need to grab the spreadsheet ID from the public URL and use it with Google Sheets API v4. That old GData API you’re using is deprecated and makes everything way harder than it needs to be. Public sheet URLs look like https://docs.google.com/spreadsheets/d/{SPREADSHEET_ID}/edit - just parse out the ID part. Then create a SheetsService without credentials and call spreadsheets().values().get() with the sheet ID and range. Way cleaner than fighting with the legacy API’s auth requirements. Plus the response data is better structured.
yep, just get the sheet ID from the public link, then use Sheets API v4 - no authentication needed for public sheets. you can make direct HTTP requests or use the Google.Apis.Sheets.v4 package instead of that outdated GData stuff.
You’re using the old GData API, which wasn’t built for this. Here’s what works better: grab the spreadsheet ID from your public URL (it’s that long string between /d/ and /edit). Then just hit https://sheets.googleapis.com/v4/spreadsheets/{SPREADSHEET_ID}/values/{RANGE} with a regular GET request. Use something like ‘Sheet1!A1:Z1000’ for the range. Since it’s public, you don’t need auth headers. I’ve been running this setup in production for over a year - way more reliable than fighting with GData auth. Just parse the JSON and you’re done. Much cleaner than SpreadsheetEntry.