【问题标题】:How can I tell if a webproperty is deleted using Google AnalyticsService?如何判断是否使用 Google AnalyticsService 删除了网络资产?
【发布时间】:2012-10-02 23:47:59
【问题描述】:

我正在使用 Google Analytics API 从我的 Analytics 帐户中获取 web property information

当我登录分析时,我只有一个网站,但通过 api 我得到了几个(旧的和已删除的网站)

我的代码是这样的:

        var provider = new WebServerClient(GoogleAuthenticationServer.Description)
                           {
                               ClientIdentifier = _appId,
                               ClientSecret = _appSecret
                           };

        var auth = new OAuth2Authenticator<WebServerClient>(provider, x => new AuthorizationState { AccessToken = token });
        var analyticsService = new AnalyticsService(auth);

        var accounts = analyticsService.Management.Accounts.List().Fetch();

        foreach (var account in accounts.Items)
        {
            var webProperties = analyticsService.Management.Webproperties.List(account.Id).Fetch();

            // todo: determine if web property is still in use?
        }

如何从代码中判断哪些仍处于活动状态?

【问题讨论】:

    标签: c# google-api google-analytics-api


    【解决方案1】:

    所以经过更多的挖掘。

    似乎没有标志或类似的东西表明它已被删除,但如果您继续深入研究结果集,您会注意到在配置文件级别,没有子项的配置文件似乎是删了一个。

    这是有道理的,我猜不会有与已删除的个人资料相关联的个人资料。

    var provider = new WebServerClient(GoogleAuthenticationServer.Description)
                               {
                                   ClientIdentifier = _appId,
                                   ClientSecret = _appSecret
                               };
    
            var auth = new OAuth2Authenticator<WebServerClient>(provider, x => new AuthorizationState { AccessToken = token });
            var analyticsService = new AnalyticsService(auth);
    
            var accounts = analyticsService.Management.Accounts.List().Fetch();
            var result = new List<Profile>();
    
            foreach (var account in accounts.Items)
            {
                var webProperties = analyticsService.Management.Webproperties.List(account.Id).Fetch();
    
                foreach (var webProperty in webProperties.Items)
                {
                    var profiles = analyticsService.Management.Profiles.List(account.Id, webProperty.Id).Fetch();
    
                    if (profiles.Items != null && profiles.Items.Any())
                    {
                        // these are the ones we want
                        result.AddRange(profiles.Items);
                    }
                }
    
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-19
      • 2021-08-19
      • 2012-08-06
      • 2015-10-11
      • 2014-02-11
      • 2012-12-31
      • 1970-01-01
      相关资源
      最近更新 更多