【问题标题】:Unexpected character encountered while parsing value: <. Path '', line 0, position 0 in GA api解析值时遇到意外字符:<。路径'',第 0 行,GA api 中的位置 0
【发布时间】:2015-08-20 12:20:19
【问题描述】:

在向 GA 发送请求之前,我使用以下 google analyics api 代码进行身份验证,但我收到错误消息

"解析值时遇到意外字符:<.path ga api>

同时通过 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",

                                               });

【问题讨论】:

  • 您忘记发布您用于 GAOuthService.Data.Ga.Get() 的代码 身份验证不会给您一个错误,因为发布代码将无济于事。

标签: c# google-api google-oauth google-analytics-api google-api-dotnet-client


【解决方案1】:

使用上面的代码,请求应该是这样的。

var request = service.Data.Ga.Get("ga:8903098", "2014-01-01", "2014-01-01", "ga:sessions");
request.MaxResults = 1000;
GaData result = request.Execute();

您的身份验证似乎正在使用变量 service 返回。除非您还使用 GAOuthService 进行身份验证,否则调用 GAOuthService.Data.Ga.Get() 可能不起作用。

你需要记住发布所有有问题的代码

【讨论】:

    猜你喜欢
    • 2018-07-25
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多