0

I am trying to use Google classroom API's to integrate into a product. For that I have created a project in developer console and also created oAuth credentials.

Downloaded the client secret json file.

I am trying to create a class in Google classroom through the API. The code I have used to get access is as follows:

 using (var stream = new FileStream(System.Web.HttpContext.Current.Server.MapPath("client_secret.json"), FileMode.Open, FileAccess.Read))
        {
                string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(@"C:\googlekeys\.credentials\classroom-dotnet-quickstart.json");

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

when executing the last step it was giving the error Error:

redirect_uri_mismatch

I have cross checked between the developer console and json file that both have the same redirect uris. I have done this process previously for other domains and it has worked great.

Confusing thing for me is that for each and every time I run the code, the redirect uri in the url is changing.

run 1: The redirect URI in the request, http://localhost:51282/authorize/, does not match the ones authorized for the OAuth client

run 2: The redirect URI in the request, http://localhost:44699/authorize/, does not match the ones authorized for the OAuth client

I am very much confused from where it is picking up that redirect url.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
allenXY
  • 1
  • 1
  • 1
    Your IDE is applying a random port number every time you run it in debug. You need to stop it from doing that. – Linda Lawton - DaImTo Jun 29 '16 at 09:52
  • I think GoogleWebAuthorizationBroker.AuthorizeAsync() will take redirecturi from the client_secrete.json file right ? .if it was taking from that file it should be same every time right ? – allenXY Jun 30 '16 at 08:07
  • 1
    And googles web servers will know if you are not sending it from that location. You have to be sending it from the same place that you have set up in Google developers console. – Linda Lawton - DaImTo Jun 30 '16 at 08:09
  • I'm using VS:2013 and every time i run my project its port number is being constant it is not changing , but the redirect_uri is changing ... – allenXY Jun 30 '16 at 10:33

0 Answers0