Google 分析 api 集成问题
Google analytics api integration issue
我正在使用 signet and google-api-ruby-client 与 Google Analytics api、
集成
编写了以下代码:
require 'signet/oauth_2/client'
require 'google/apis/analytics_v3'
class GoogleController < ApplicationController
skip_before_action :ensure_json_request
def analytics_login
client = initialize_client
redirect_to(client.authorization_uri.to_s)
end
def analytics_callback
client = initialize_client
client.code = params['code']
authorization = client.fetch_access_token!
anal = Google::Apis::AnalyticsV3::AnalyticsService.new
anal.authorization= authorization
accounts = anal.list_account_summaries(max_results: 100, options: {authorization: authorization})
pp accounts.items.first.web_properties.first.profiles.first.id
redirect_to('http://0.0.0.0:3000')
end
private
def initialize_client
Signet::OAuth2::Client.new(
:authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
:token_credential_uri => 'https://www.googleapis.com/oauth2/v3/token',
:client_id => '*******.apps.googleusercontent.com',
:client_secret => '******',
:scope => Google::Apis::AnalyticsV3::AUTH_ANALYTICS,
:redirect_uri => 'http://localhost:3000/ga/callback'
)
end
结束
我正在进入回调并在 /ga/callback 收到一个 Google::Apis::AuthorizationError 错误作为调用 list_account_summaries.
的响应
我错过了什么吗?
进一步挖掘后发现了一个有效的样本here
我正在使用 signet and google-api-ruby-client 与 Google Analytics api、
集成编写了以下代码:
require 'signet/oauth_2/client'
require 'google/apis/analytics_v3'
class GoogleController < ApplicationController
skip_before_action :ensure_json_request
def analytics_login
client = initialize_client
redirect_to(client.authorization_uri.to_s)
end
def analytics_callback
client = initialize_client
client.code = params['code']
authorization = client.fetch_access_token!
anal = Google::Apis::AnalyticsV3::AnalyticsService.new
anal.authorization= authorization
accounts = anal.list_account_summaries(max_results: 100, options: {authorization: authorization})
pp accounts.items.first.web_properties.first.profiles.first.id
redirect_to('http://0.0.0.0:3000')
end
private
def initialize_client
Signet::OAuth2::Client.new(
:authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
:token_credential_uri => 'https://www.googleapis.com/oauth2/v3/token',
:client_id => '*******.apps.googleusercontent.com',
:client_secret => '******',
:scope => Google::Apis::AnalyticsV3::AUTH_ANALYTICS,
:redirect_uri => 'http://localhost:3000/ga/callback'
)
end
结束
我正在进入回调并在 /ga/callback 收到一个 Google::Apis::AuthorizationError 错误作为调用 list_account_summaries.
的响应我错过了什么吗?
进一步挖掘后发现了一个有效的样本here