【问题标题】:Google Analytics API error 403: "User does not have permission to access profile"Google Analytics API 错误 403:“用户无权访问个人资料”
【发布时间】:2013-06-01 10:46:06
【问题描述】:

我一直在尝试学习如何使用 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();

它在最后一行遇到了问题,它给了我:

Google.Apis.Requests.RequestError

用户对此配置文件没有足够的权限。 [403]

我查看了here 似乎存在类似问题的地方,但它所说的只是将电子邮件作为用户添加到 API 控制台中,我这样做了。有人知道我需要改变什么吗?

【问题讨论】:

  • 您是否已在您的 Google Analytics(分析)中将 xxxxxxxx@developer.gserviceaccount.com 注册为管理员级别的用户?
  • 是的,我试过了,它仍然给我同样的错误

标签: google-analytics google-api google-analytics-api google-api-dotnet-client


【解决方案1】:

只是为了确认——在原始帖子中,您说您在“API 控制台”中添加了电子邮件。但您实际上需要使用 Analytics Web UI 将电子邮件添加到您的 Google Analytics Profile 中。是你做的吗?仅当您发出请求的用户 ID 不在分析配置文件中时,才会出现此错误。

【讨论】:

  • 是的。这正是我所提到的
  • 我现在真的很傻,原来我只是输入了错误的帐号。谢谢大家!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-11
相关资源
最近更新 更多