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"
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[] {
AnalyticsService.Scope.Analytics,
AnalyticsService.Scope.AnalyticsEdit,
AnalyticsService.Scope.AnalyticsManageUsers,
AnalyticsService.Scope.AnalyticsManageUsersReadonly,
AnalyticsService.Scope.AnalyticsProvision,
AnalyticsService.Scope.AnalyticsReadonly},
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; }
}
}
I have found that you have solved this thread, here is the stackoverflow link:
http://stackoverflow.com/questions/37267140/url-mismatch-while-authenticating-google-analyticsservice. It is better to share your solutions and experience here. It will be very beneficial for other community members who have similar questions. If you have
any difficulty in future programming, we welcome you to post in forums again.
Regards
Jambor
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
Member
20 Points
195 Posts
URL mismatch while authenticating google AnalyticsService
May 17, 2016 06:21 AM|mrhammad|LINK
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.
Contributor
3325 Points
403 Posts
Re: URL mismatch while authenticating google AnalyticsService
May 18, 2016 02:10 AM|Jamobor yao - MSFT|LINK
Hi,
I have found that you have solved this thread, here is the stackoverflow link: http://stackoverflow.com/questions/37267140/url-mismatch-while-authenticating-google-analyticsservice. It is better to share your solutions and experience here. It will be very beneficial for other community members who have similar questions. If you have any difficulty in future programming, we welcome you to post in forums again.
Regards
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.