Google Analytics API:“用户对此帐户没有足够的权限." [英] Google Analytics API: "User does not have sufficient permissions for this account."

查看:29
本文介绍了Google Analytics API:“用户对此帐户没有足够的权限."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Ruby 应用,它访问 Google Analytics API 以提取一些实验信息.

I'm writing a Ruby app that accesses the Google Analytics API to pull down some experiment information.

该应用通过以下功能使用 Google 服务帐户进行连接和身份验证:

The app connects and authenticates using a Google Service Account via the following function:

def connect
  ...
  @@client = Google::APIClient.new(:application_name => 'My Service App', 
                                    :application_version => '1.0.0')
  key_file = Rails.root.join('config', 'privatekey.p12').to_s
  key_secret = 'somesecret'
  key = Google::APIClient::PKCS12.load_key(key_file, key_secret)
  asserter = Google::APIClient::JWTAsserter.new(
    SECRETS[:google_service_account_email],
    ['https://www.googleapis.com/auth/yt-analytics.readonly',
     'https://www.googleapis.com/auth/analytics.readonly'
    ],
    key
  )
  @@client.authorization = asserter.authorize()
  ...
end

...它可以毫无问题地验证和发现两个 API.

...which authenticates and discovers both APIs without issue.

针对 YouTube 分析 API 使用客户端没有问题.使用完全相同的帐户通过以下方式访问 Analytics API...

Using the client against the YouTube Analytics API works without issue. Using the same exact account to access the Analytics API via...

response = @@client.execute({
  # 'analytics is the API object retrieved via discover_api()
  :api_method => analytics.management.experiments.list, 
  :parameters => {
    'accountId' => 'AAAAAAAA',
    'profileId' => 'PPPPPPPP',
    'webPropertyId' => 'UA-WWWWWWWW-#'
  }
})

导致 403 错误响应:

Results in a 403 error response:

{"domain":"global","reason":"insufficientPermissions","message":"User does not have sufficient permissions for this account."}

关于授权,我已经仔细检查了帐户service@myapp.com:

In regards to authorization, I have double-checked the account service@myapp.com:

  • 对 Google Analytics 网络界面拥有完全权限.我使用 service@myapp.com 帐户登录,并且能够查看我尝试列出的相同实验.
  • 已启用 Analytics API.在 API 控制台中,我在服务"部分确认了 Analytics API 项已切换到 ON.(就像 YouTube 数据分析一样.)
  • 我使用了适当的 AccountID、ProfileID 和 WebPropertyID 值.直接从 Google Analytics 网络界面复制.
  • Has full permissions to the Google Analytics web interface. I logged in using the service@myapp.com account and was able to view the same Experiments I attempted to list.
  • Has enabled the Analytics API. Within the API Console, I confirmed in the Services section that the Analytics API item is switch to ON. (Just like YouTube Analytics is.)
  • I am using the appropriate AccountID, ProfileID, and WebPropertyID values. Copied directly from the Google Analytics web interface.

鉴于服务帐户可以访问至少一个 API(YouTube 分析),并且关联帐户 (service@myapp.com) 可以访问分析网络界面,因此访问分析的服务帐户似乎有问题尤其是 API.

Given that the service account can access at least one API (YouTube Analytics), and the associated account (service@myapp.com) can access the Analytics web interface, there seems to be something wrong with the service account accessing the Analytics API in particular.

有什么想法吗?

相似主题:

  • "Not sufficient permissions" google analytics API service account (NOTE: This error is slightly different than mine)
  • Analytics blog post, check comments section for 'permissions'

推荐答案

确保您授予服务帐户电子邮件(类似于 1234567890@developer.gserviceaccount.com)从 GA 视图读取/写入的权限.

Make sure you give the service account email (something like 1234567890@developer.gserviceaccount.com) permissions to read/write from your GA view.

管理>查看>用户管理>添加权限:"

Admin > View > User Management > "Add permissions for:"

这篇关于Google Analytics API:“用户对此帐户没有足够的权限."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆