2013-11-28 47 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/