Can't get Google Analytics user data to show in Rails app -


i'm attempting server-to-server connection between google analytics account , rails app. this, i'm using legato, omniauth-google-oauth2, , google-api-client gems. intention have rake task sieves out pageview data particular site. however, can't seem user data out of it. here's code:

require 'google/api_client' def service_account_user(scope="https://www.googleapis.com/auth/analytics.readonly")    client = google::apiclient.new(      :application_name => "listmaker",      :application_version => "2.0"    )    key = openssl::pkey::rsa.new(figaro.env.google_private_key, "notasecret")    service_account = google::apiclient::jwtasserter.new(figaro.env.google_app_email_address, scope, key)    client.authorization = service_account.authorize    oauth_client = oauth2::client.new("", "", {       :authorize_url => 'https://accounts.google.com/o/oauth2/auth',       :token_url => 'https://accounts.google.com/o/oauth2/token'    })    token = oauth2::accesstoken.new(oauth_client, client.authorization.access_token)    legato::user.new(token) end  class pageviews     extend legato::model      metrics :pageviews     dimensions :page_path     filter :for_page_path, &lambda {|page_path| matches(:page_path, page_path)} end  puts profile = service_account_user.profiles.first 

i appear getting empty array profile variable after running task. i've added developer email address google analytics view i'm interested in. not sure what's wrong.

for service account work google analytics service account email must added @ account level. wont work if added @ view level.


Comments

Popular posts from this blog

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

php - facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1 -

hadoop - Sqoop installation export and import from postgresql -