2013-11-28 43 views
2

我們試圖通過google analytics api v3從單個管理員用戶那裏獲取所有谷歌帳戶配置文件的列表。谷歌分析API v3無法檢索用戶管理員的數據

我們有一個用戶([email protected]),它是多個域的多個帳戶的管理員,但不是其中任何一個域的所有者,也沒有個人分析帳戶。

  1. 我們創建了一個新的控制檯項目。
  2. 在我們的用戶[email protected]
  3. 從nuget包導入dll,如在this tutorial中建議的在谷歌控制檯中創建遠程服務。
  4. 寫了這個簡單的代碼來測試連接,並得到我們的用戶的配置文件列表後this example

    公共類節目 { 公共靜態無效的主要(字串[] args){ // privatekey.p12已被下載,並與路徑 VAR證書簡稱=新X509Certificate2(@ 「privatekey.p12」,「 notasecret「,X509KeyStorageFlags.Exportable);

    // this email was provided by google service account 
    var initializer = new ServiceAccountCredential.Initializer("[email protected]ccount.com") 
            { 
             Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly }, 
             // this is the name of one profile account admin 
             User = "name" 
            }.FromCertificate(certificate); 
    
    // Create the service. 
    var service = new AnalyticsService(new BaseClientService.Initializer() 
    { 
        HttpClientInitializer = new ServiceAccountCredential(initializer), 
        // this is our application name on google service account 
        ApplicationName = "app name", 
    }); 
    
    var services = service.Management.Profiles.List("~all", "~all").Execute(); 
    

    }}

當我們試圖讓文件列表中,我們得到這個錯誤

Error:"invalid_grant", Description:"", Uri:"" .. 

任何幫助感激,感謝。

回答

1

你不能直接查詢配置文件。你需要去雖然帳戶 - >網絡媒體則 - >輪廓

//獲取帳戶

ManagementResource.AccountsResource.ListRequest AccountListRequest = service.Management.Accounts.List(); 
Accounts AccountList = AccountListRequest.Execute(); 

//查找帳戶你想

Account Daimto = AccountList.Items.Where(a => a.Name.ToLower().Contains("daimto")).First(); 

//獲取網絡性能該帳戶

service.Management.Webproperties.List(Daimto.Id); 
Webproperties WebPropertyList = WebPropertyListRequest.Execute(); 

//在網上找到物業你想

Webproperty DaimtoWP = WebPropertyList.Items.Where(a => a.Name.ToLower().Contains("daimto")).First(); 

//獲取配置文件是網絡媒體資源

ManagementResource.ProfilesResource.ListRequest ProfileListRequest = service.Management.Profiles.List(Daimto.Id,DaimtoWP.Id); 
Profiles ProfileList = ProfileListRequest.Execute(); 

這一切都是從我的博客文章拷入:http://daimto.com/google-analytics-api-v3-with-c/