我在向GA发送请求之前使用以下google analyics api代码进行身份验证,但我收到错误消息
"解析值时遇到意外的字符:<。路径'', 第0行,GA api中的位置0"
通过执行请求
GAOuthService.Data.Ga.Get()
方法
我的验证码
var scopes = new[] { AnalyticsService.Scope.Analytics,
AnalyticsService.Scope.AnalyticsEdit,
AnalyticsService.Scope.AnalyticsManageUsers,
AnalyticsService.Scope.AnalyticsReadonly};
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
, scopes
, userName
, CancellationToken.None
, new FileDataStore("GoogleAnalytics.Auth.Store")).Result;
var service = new AnalyticsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "xyz",
});
答案 0 :(得分:1)
使用上面的代码,请求的外观如下。
var request = service.Data.Ga.Get("ga:8903098", "2014-01-01", "2014-01-01", "ga:sessions");
request.MaxResults = 1000;
GaData result = request.Execute();
您的身份验证似乎是使用变量服务返回的。除非您还使用 GAOuthService 进行身份验证,否则调用GAOuthService.Data.Ga.Get()
可能无法正常工作。
你需要记住发布所有有问题的代码