0

I'm trying to follow the quickstart tutorial for Google Sheets .NET API here.

But when it gets to this line:

            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;

Here's what happens:

  1. Internet Explorer opens.

  2. Goes to accounts.google.com application authorization window.

  3. I click Allow.

  4. Get redirected to localhost. Get this message in IE.


This page can't be displayed

* Make sure the web address http://localhost:54538 is correct.
* Look for the page with your search engine.
* Refresh the page in a few minutes.
  1. In VS Express, this exception is thrown:

An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll

Additional information: One or more errors occurred.

It's possible that there is a corporate IT security policy in place that is preventing me from accessing this localhost port; I tried directly typing "localhost" and "127.0.0.1" into the Chrome address bar, and in both cases got a "This site can’t be reached" error.

EDIT: My client_id.json file is as follows:

{"installed":{"client_id":"[long ID string].apps.googleusercontent.com","project_id":"angular-polygon-162522","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"[secret ID]","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
sigil
  • 9,370
  • 40
  • 119
  • 199
  • Try to check these SO questions [11122092](http://stackoverflow.com/questions/11122092/how-to-fix-system-aggregateexception-occurred-in-mscorlib-dll) and [30647119](http://stackoverflow.com/questions/30647119/system-aggregateexception-occurred-in-mscorlib-dll-when-using-signalr) if it can help you. – KENdi Mar 25 '17 at 04:43
  • Do you have an http server running at "http://localhost:54538"? Did you try entering "http://localhost:54538" in your browser (you said you entered "http://localhost")? What do you expect to see next? – pinoyyid Mar 28 '17 at 11:10
  • @pinoyyid, I entered `localhost:54538` in the browser and got "This site can’t be reached, localhost refused to connect." I don't have an http server running there, I'm just trying to diagnose why `AuthorizeAsync()` is failing. – sigil Apr 03 '17 at 20:55
  • It's failing because you don't have an http server running on port 54538. What is in your credentials file (obfuscate any secrets) – pinoyyid Apr 04 '17 at 03:47
  • @pinoyyid, I've added the contents of the `client_id.json` file that I received from Google when I registered the app, in the body of my question. – sigil Apr 05 '17 at 16:47
  • @pinoyyid, any further advice about this? I'm just trying to automate some data entry into a Google Sheets document using C#, is there a simpler way to do this? – sigil Apr 28 '17 at 17:37
  • Sure. let me ask, will it always be the same Sheet? or will each user of your app have his own sheet? – pinoyyid Apr 28 '17 at 18:31
  • @pinoyyid, for this app, there will be multiple users all accessing the same sheet. – sigil May 09 '17 at 07:36
  • is your app running on a server, or is it distributed and installed to user's own PCs? – pinoyyid May 09 '17 at 10:03
  • @pinoyyid, it may run on a server eventually, but for now I'd like to make it a standalone executable that each user can run on their own PC. – sigil May 09 '17 at 20:29
  • I suggest you create a Service Account. Your app will be able to authenticate to this using saved credentials. So no more 3-legged OAuth to worry about. You will need to share the spreadsheet with the email address of the Service Account so that it can be accessed. – pinoyyid May 09 '17 at 21:08

0 Answers0