0

Greetings to all of you.

I have This code working fine to connect to Google sheets API from WPF (Desktop Application C# ) application.

My question: Is it possible to modify it to work in .net Maui application( Application Mobile , Desktop C#)

My code:

//connection Google sheets API

string[] Scopes = { SheetsService.Scope.Spreadsheets };
var service = new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = " My Client ID", ClientSecret = "My Client secret" }, Scopes, "user", CancellationToken.None, new FileDataStore("MyAppsToken")).Result, ApplicationName = " My Application ", });
   var values = service.Spreadsheets.Values.Get("My Spread Sheets ID", $"{"My sheet Name"}!A:C").Execute().Values;

I've tried changing the settings Google console from Application Desktop to web application , but to no avail.

  • We don't support mobile platforms in the Google libraries at the moment. Other than auth, I'd *expect* it all to work - and you may well be able to get auth to work by implementing a suitable ICodeReceiver, but it's not something we provide. – Jon Skeet Mar 08 '23 at 09:38
  • (As an aside, I'd strongly advise reformatting/rewriting your code *at least for Stack Overflow* to avoid long lines. Currently your service declaration line is nearly 350 characters long, which makes it really hard to read.) – Jon Skeet Mar 08 '23 at 09:39

1 Answers1

0

You can use the following code for MAUI Windows APP, this will not work for android due to loop-back flow issue from google:

private static string[] SCOPES =
{
    SheetsService.Scope.Spreadsheets
};

SheetsService service = new SheetsService(new
    BaseClientService.Initializer()
    {
        HttpClientInitializer =
    GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets()
            {

                ClientId = WIN_CLIENT_ID,
                //This should be you client id from json

                ClientSecret = WIN_CLIENT_SECRET,
                //this should be your secret key

            }, SCOPES, "user", CancellationToken.None, new FileDataStore("MyAppToker")).Result, ApplicationName = APP_NAME
    });
Govind
  • 51
  • 7