作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试学习如何使用Google Analytics(分析)API来获取网站流量数据。我一直遇到一个错误,说用户没有访问配置文件的权限。我从服务帐户向用户添加了电子邮件地址,并尝试使其成为具有所有配置文件访问权限的用户和管理员,但均无法正常工作。
这是我的代码,是从here获得的:
string scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue();
string clientId = "xxxxxxxx@developer.gserviceaccount.com";
string keyFile = @"C:\Users\emorris\Downloads\xxxxxxxxxx-privatekey.p12";
string keyPassword = "notasecret";
AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;
X509Certificate2 key = new X509Certificate2(keyFile, keyPassword, X509KeyStorageFlags.Exportable);
AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId= clientId, Scope = scope };
OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
AnalyticsService gas = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = auth });
DataResource.GaResource.GetRequest r = gas.Data.Ga.Get("ga:xxxxxx", "2013-05-01", "2013-05-31", "ga:visitors");
GaData d = r.Fetch();
最佳答案
只是为了确认-在原始帖子中,您说过您已在“ API控制台”中添加了电子邮件。但实际上,您实际上需要使用Google Analytics(分析)网络用户界面将电子邮件添加到您的Google Analytics(分析)配置文件中。是你做的吗?仅当您发送请求的用户ID不在分析配置文件中时,才会发生此错误。
关于google-analytics - Google Analytics API错误403:“用户无权访问个人资料”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16944933/
我是一名优秀的程序员,十分优秀!