我们正试图通过google analytics api v3从单个管理员用户获取所有Google帐户 Profiles 的列表 .
我们有一个用户(admin@company.com),该用户是多个域的多个帐户的管理员,但不是其中任何一个的所有者,并且没有个人分析帐户 .
-
我们创建了一个新的控制台项目 .
-
使用我们的用户admin@company.com在this tutorial中建议的谷歌控制台中创建远程服务
-
从nuget包导入dll .
-
编写了这个简单的代码来测试连接,并在this example之后获取用户的配置文件列表 .
public class Program {public static void Main(string [] args){// privatekey.p12已下载并引用路径var certificate = new X509Certificate2(@“privatekey.p12”,“notasecret”,X509KeyStorageFlags.Exportable);
// this email was provided by google service account
var initializer = new ServiceAccountCredential.Initializer("xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.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();
}}
当我们尝试获取 Profiles 列表时,我们会收到此错误
Error:"invalid_grant", Description:"", Uri:"" ..
任何帮助欣赏,谢谢 .
2 回答
您无法直接查询配置文件 . 您需要通过帐户 - >网络媒体资源然后 - > Profiles
//获取帐户
//找到你想要的帐户
//获取该帐户的网络媒体资源
//找到你想要的网络资产
//获取该webproperty的配置文件
这全部都是从我的博客文章中复制而来的:http://daimto.com/google-analytics-api-v3-with-c/
问题是NTP时间 .
https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtAuthorization
第"Troubleshooting"节