4

I have a website in Visual Studio Express 2012 for Web.

I keep getting an error from google which says there isn't a match for the redirect uri's listed in the developer console when I try the code below:

private void getEvents()
    {
        UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
               new ClientSecrets
               {
                   ClientId = "CLIENTIDHERE",
                   ClientSecret = "SECRETHERE",
               },
               new[] { CalendarService.Scope.Calendar },
               "user",
               CancellationToken.None).Result;

        // Create the service.
        var service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential
        });

        List<Event> x = service.Events.List("primary").Execute().Items.ToList();
    }

I have already tried setting the default port to 8080 in visual studio and the URI's listed in my developer console are as follows:

http://localhost:8080/QFC/Coach/Manageusers.aspx

http://localhost:8080/QFC/*

http://localhost:8080/oauth2callback

http://localhost:8080/oauth2callback/

http://localhost:8080/authorize

http://localhost:8080/authorize/

http://localhost:8080/signin-google

The code mentioned above is called from http://localhost:8080/QFC/Coach/Schedule.aspx on page load. Each time I get the error the port number is different and I have no idea why. e.g. http://localhost:57002/authorize/ did not match a registered

I am using the .NET api with C#

I need to know why it's doing this and how to fix it.

msbarnard
  • 644
  • 2
  • 8
  • 19

2 Answers2

5

Added http://localhost/authorize/ to the list of allowed URI's. This somehow makes google verification ignore the port. But it works!

msbarnard
  • 644
  • 2
  • 8
  • 19
  • I'm having the same problem and tried to add so many different URIs, also http(s)://localhost/authorize. The problem is that the port always changes and Google doesn't ignore it! Did you also configure the OAuth2 authentication service for Google in your Project? – Cheshire Cat Mar 11 '15 at 07:25
  • No I didn't... I struggled for a long time with this, and adding that line to the list of allowed URI's just fixed it. I did nothing else. – msbarnard Mar 17 '15 at 13:17
3

In my case I was doing the quickstart with no prior knowledge of Google Calendar API. The solution was adding:

http://localhost/

and waiting a few minutes for an update

juan Isaza
  • 3,646
  • 3
  • 31
  • 37