3

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!

2 Answers2

1

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

  • Very valid, thank you. But now looks like I have some other issue. If you open this screenshot http://prntscr.com/gatyaq on "GoogleWebAuthorizationBroker.AuthorizeAsync" I receive exception "Failed to launch browser with \"https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&resp…". I read that this could be coming from client_secret.json. But I just download it from here "http://prntscr.com/gatytp" and add it to project. –  Aug 20 '17 at 16:33
  • Which platform you are targeting? – Vijendra Ram S Aug 21 '17 at 07:25
  • The source that you see is inside Android project. Target version "Use Compile using SDK version" and target framework "Android 7.0" –  Aug 21 '17 at 07:30
  • Screen shot attached code failing to lunch browser due to android platform some how. Try alternate method using Android API https://developers.google.com/sheets/api/quickstart/android – Vijendra Ram S Aug 21 '17 at 08:39
  • From what I see in github.com/xamarin/google-apis this is only for Android, in my case I have Xamarin.Forms so I would need it for IOS as well or in PCL. Similar the case with android quickstart that you send. I would need it in that case for IOS as well and in fact I run the application, not in emulator, but on my real device (Samsung Galaxy S6 Edge) –  Aug 21 '17 at 22:43
  • Create new question someone might have answer. :) – Vijendra Ram S Aug 22 '17 at 07:25
  • I referenced my issue into new question "https://stackoverflow.com/questions/45827730/xamarin-forms-google-auth-error". Thank you for help @Vijendra –  Aug 22 '17 at 22:08
1
public IList<Google.Apis.Drive.v3.Data.File> GetAllFiles()
{
    // Define parameters of request.
    FilesResource.ListRequest listRequest = service.Files.List();
    listRequest.PageSize = 10;
    listRequest.Q = "mimeType='application/vnd.google-apps.spreadsheet'";

    // List files.
    return  listRequest.Execute().Files;
}
Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
Sandip Shelke
  • 11
  • 1
  • 3