2012-10-02 61 views
0

我使用Google Analytics API從我的Google Analytics帳戶獲取web property information如何判斷使用Google AnalyticsService刪除網站媒體資源?

當我登錄到analaytics雖然,我只有一個網站,但通過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? 
     } 

從代碼如何我可以告訴哪些人仍然活躍?

回答

0

所以多挖一點。

似乎沒有任何標誌或任何類似標誌表明它已被刪除,但如果您繼續深入研究結果集,您會注意到在配置文件級別,沒有子項目的配置文件似乎是刪除一個。

這是有道理的我猜那裏不會有一個配置文件與那些已被刪除。

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); 
       } 
      } 

     } 
    } 
相關問題