我希望从我公司的GA帐户中获取行为报告。
我使用了以下代码。
`
require 'google/apis/analytics_v3'
require 'googleauth'
scope = 'https://www.googleapis.com/auth/analytics.readonly'
analytics = Google::Apis::AnalyticsV3::AnalyticsService.new
analytics.authorization = Google::Auth::ServiceAccountCredentials.make_creds({
"json_key_io": Rails.root.join('/GoogleAnalyticsXXXXX.json'),
"scope": scope
})
analytics.authorization.fetch_access_token!
end
end
analytics.get_ga_data('ga:XXXXXX', Time.now.to_date.to_s, Time.now.to_date.to_s, "ga:sessions,ga:pageviews")
但它会引发错误。
Error - #<Google::Apis::ClientError: insufficientPermissions: User does not have any Google Analytics account.>
Google::Apis::ClientError: insufficientPermissions: User does not have any Google Analytics account.
from /Users/user_name/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.13.3/lib/google/apis/core/http_command.rb:218:in check_status' from /Users/user_name/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.13.3/lib/google/apis/core/api_command.rb:116:incheck_status'
from /Users/user_name/.rvm/gems/ruby-2.2.2/gems/google-api-client-0.13.3/lib/google/apis/core/http_command.rb:183:in `process_response'
请让我知道我错过了什么