无法使用google-api-client gem扩展google api范围

时间:2014-08-26 11:00:06

标签: ruby google-analytics google-api sinatra

我按照为google-api-ruby-client gem提供的示例:https://github.com/google/google-api-ruby-client-samples/blob/master/calendar/calendar.rb

工作正常。所以我想将它与Google Analytics一起使用并进行以下更改(其他一切与示例中的相同):

...
def analytics_api; settings.analytics; end
...

configure do
  ...

  client.authorization.scope = [
    'https://www.googleapis.com/auth/calendar',
    'https://www.googleapis.com/auth/analytics' # <- Here I added Analytics
  ]

  ...

  analytics = client.discovered_api('analytics', 'v3')
  set :analytics, analytics
end

...

get '/' do
  result = api_client.execute(:api_method => analytics_api.management.accounts.list,
                              :parameters => {},
                              :authorization => user_credentials)
  [result.status, {'Content-Type' => 'application/json'}, result.data.to_json]
end

我还在Google Developer Console API列表中激活了Google Analytics(就像我为日历所做的那样),然后重新启动了服务器。

但是,当我查看http://localhost:4567时(是的,我正在使用Sinatra),我没有获得新的授权请求google页面(适用于Google Analytics),并显示以下消息:

{"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"Insufficient Permission"}],"code":403,"message":"Insufficient Permission"}}

似乎API并未考虑新范围。它仍适用于日历,但不适用于Google Analytics。

有什么想法吗?感谢。

0 个答案:

没有答案