403 Insufficient permissions error while trying to get Google Analytics data

亡梦爱人 提交于 2019-12-24 06:45:00

问题


I'm developing RoR application, which allows user to login with google account and download/upload report data from one of his analytics account. I use omniauth-google-oauth2 gem for authorization with google account and google-api-client for interaction with Google Analytics. The problem is that when I try to get accounts list with analytics.management.accounts.list method, passing google token as one of authorization parameters, GA responds with 403 Insufficient permissions error.

I suppose, I have to make user to give permission for reading Analytics data in process of authorization. How can I do this?

I've read a lot of related questions, but didn't find solution to my exact problem.

Here is the code:

require 'google/api_client'

client = Google::APIClient.new(:application_name => 'something you like', :application_version => '1')

client.authorization.access_token = 'HERE_GOES_TOKEN'

ga = client.discovered_api('analytics', 'v3')

client.execute(:api_method => ga.management.accounts.list)

回答1:


Solved the problem! I had to write proper scopes in OAuth configs.

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, PROVIDER_KEY, PROVIDER_SECRET,
  {
    :scope => "email, profile, https://www.googleapis.com/auth/analytics, https://www.googleapis.com/auth/analytics.edit, https://www.googleapis.com/auth/analytics.manage.users, https://www.googleapis.com/auth/analytics.readonly",
  }
end


来源:https://stackoverflow.com/questions/24778990/403-insufficient-permissions-error-while-trying-to-get-google-analytics-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!