Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets API, Get Spreadsheets for user in C#

I am developing Xamarin.Forms application and what I am trying to do is:

  • Authenticate user in Google with Auth0 2.0
  • After that I receive token response
  • Get all spreadsheets inside user's account

Currently, I know that Google updated quite a lot their API with latest version and I no more can use SpreadsheetsService. What I see in official documentation is that they're using SheetsService, at least that's what they've here.

This is my code right now:

var service = new SheetsService(new BaseClientService.Initializer
{
    HttpClientInitializer = this.userCredential,
    ApplicationName = Statics.StaticStrings.AppDomain.ApplicationName
});

var spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
var range = "Class Data!A2:E";
SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadsheetId, range);

So far it's working, but the problem that I have is that I can get spreadsheet if I have it's ID, but I am not sure from where I can get it and, of course I don't want to hard code it (makes no sense).

this.userCredential is field from type Google.Apis.Auth.OAuth2.UserCredential, where I pass (IAuthorizationCodeFlow flow, string userId, TokenResponse token), so after I pass token I expect that my user will be already logged in.

My question here is, how can I get all spreadsheets to which authenticated user is authorized, so I can use them after that?

Thanks in advance!


1 Answers

The Sheets API v4 does not provide this specific operation. Here is Why.

You can do using Google Drive API's

https://developers.google.com/drive/v3/reference/#Files https://developers.google.com/drive/v3/reference/files/list

like image 119
Vijendra Ram S Avatar answered Feb 17 '26 18:02

Vijendra Ram S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!