0

I have asp.net mvc project hosted on windows azure, i am using google analytic service and its authenticating properly on my localhost however on hosted server it does not work. it gives me this error "the redirect URI in the request, callback, does not match the ones authorized for the OAuth client"

My hosted URL is "http://mysite.azurewebsites.net/" and the callback url i am giving in google console is "http://ispycms.azurewebsites.net/Dashboard/Index"

Below is the C# code for authenticating to google analytic, note that i am using service instance to make request, i have placed this code in Index method of Controller Dashboard.

    [SessionExpireFilter]
    public ActionResult Index()
    {                
            var result = new AuthorizationCodeMvcApp(this, new AppAuthFlowMetadata()).
                    AuthorizeAsync(CancellationToken.None);

            if (result.Result.Credential != null)
            {
                service = new AnalyticsService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = result.Result.Credential,
                    ApplicationName = "iSPY Stats"
                });                    
            }

//Request data 
            // make a request
        var request = service.Data.Ga.Get(
            "ga:" + profileId,
            "2016-01-01",
            "2016-05-05",
            "ga:totalEvents");
        request.Dimensions = "ga:eventCategory,ga:eventAction,ga:eventLabel,ga:date,ga:hour,ga:minute";
        request.Filters = "ga:eventCategory==Pack;ga:eventAction==Open";

        // run the request and get the data
        return request.Execute();
Hammad Nasir
  • 119
  • 1
  • 11
  • Check the error message it should give you the url you are calling from. You can use that in redirect uri. – Linda Lawton - DaImTo May 17 '16 at 06:40
  • The redirect URI in the request, https://mysite.azurewebsites.net/.auth/login/google/callback, does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/1016684719145-d4khidqovk6oano8dktdk2mnqrooprg1.apps.googleusercontent.com?project=1016684719145 to update the authorized redirect URIs – Hammad Nasir May 17 '16 at 06:59
  • then set google developer console redirect uri to mysite.azurewebsites.net/.auth/login/google/callback – Linda Lawton - DaImTo May 17 '16 at 06:59
  • thanks @DaImTo .... its working now.. however i am facing another issue .. i am getting access denied error " System.Net.HttpListenerException: Access is denied" .. below is snippet of stack trace. .. [HttpListenerException (0x5): Access is denied] System.Net.HttpListener.SetupV2Config() +333 System.Net.HttpListener.Start() +297 Google.Apis.Auth.OAuth2.d__6.MoveNext() +188 – Hammad Nasir May 17 '16 at 07:07
  • that's something in azure I think. http://stackoverflow.com/questions/4019466/httplistener-access-denied – Linda Lawton - DaImTo May 17 '16 at 07:08

0 Answers0