URL mismatch while authenticating google AnalyticsService RRS feed

  • Question

  • User588019485 posted

    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.

    public  class DashboardController:Controller
    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();
    } }

     public class AppAuthFlowMetadata : FlowMetadata
            private static readonly IAuthorizationCodeFlow flow =
                new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                        ClientSecrets = new ClientSecrets
                            ClientId = "1016684719145-....................",
                            ClientSecret = "YoXh............."
                        Scopes = new[] {
                        DataStore = new FileDataStore("Analytics.Auth.Store")
            public override string GetUserId(Controller controller)
                // In this sample we use the session to store the user identifiers.
                // That's not the best practice, because you should have a logic to identify
                // a user. You might want to use "OpenID Connect".
                // You can read more about the protocol in the following link:
                // https://developers.google.com/accounts/docs/OAuth2Login.
                var user = controller.Session["user"];
                if (user == null)
                    user = Guid.NewGuid();
                    controller.Session["user"] = user;
                return user.ToString();
            public override IAuthorizationCodeFlow Flow
                get { return flow; }

    Tuesday, May 17, 2016 6:21 AM

All replies