【问题标题】:Get Google analytics data using Oauth token?使用 Oauth 令牌获取 Google 分析数据?
【发布时间】:2017-12-10 01:45:20
【问题描述】:
【问题讨论】:
标签:
asp.net
google-analytics
【解决方案1】:
久而久之就会成功.....
这是由 Google 开发人员制作的 Oauth Playground,您可以测试您的数据
https://code.google.com/oauthplayground/
我只是使用 Oauth 2.0 来检索访问令牌信息,然后我使用以下 URL 来获取分析信息。
https://developers.google.com/analytics/devguides/reporting/core/v2/gdataReferenceDataFeed
您需要使用您的 URL 传递访问令牌,即:
https://www.googleapis.com/analytics/v2.4/data?ids=ga:12345&metrics=ga:visitors,ga:bounces&start-date=2012-07-01&end-date=2012-07-25&access_token=ya29.AHES6ZTzNR6n6FVcmY8uar6izjP9UGeHYNO5nUR7yU2bBqM
祝你好运享受编码..
【解决方案2】:
你可以试试下面的代码
string ClientId = "CLIENTID"
string ClientSecret = "CLIENTSECRET"
var Client = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret);
var Auth = new OAuth2Authenticator<NativeApplicationClient>(Client, Authenticate);
var Service = new AnalyticsService(Auth);
var Request = Service.Data.Ga.Get("profileID", StartDate, EndDate, "Matrix");
Request.MaxResults = 1000;
Request.Dimensions = "Dimensions";
var Result = Request.Fetch();