Code Monkey home page Code Monkey logo

Comments (5)

YasuakiOmokawa avatar YasuakiOmokawa commented on July 28, 2024

I solved that by using gem below.

https://github.com/carnesmedia/google-oauth2-installed

but I choose "Installed application", so it's may not correct way for your
case.

2015-06-04 23:49 GMT+09:00 Alok Swain [email protected]:

Hi,
I am using the Signet gem to get OAuth2 access token for a service
account. We are using Garb to fetch data from GA and display more logically
for our consumers.

I tried the following
Garb::Session.access_token = access_token
Garb::Management::Profile.all
and I encountered the following error:

NoMethodError: undefined method get' for #<String:0xcd585ac> from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/garb-0.9.8/lib/garb/request/data.rb:94:inoauth_user_request'
from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/garb-0.9.8/lib/garb/request/data.rb:41:in send_request' from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/garb-0.9.8/lib/garb/management/feed.rb:21:inresponse'
from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/garb-0.9.8/lib/garb/management/feed.rb:13:in parsed_response' from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/garb-0.9.8/lib/garb/management/feed.rb:17:inentries'
from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/garb-0.9.8/lib/garb/management/profile.rb:14:in all' from (irb):16 from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.19/lib/rails/commands/console.rb:47:instart'
from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.19/lib/rails/commands/console.rb:8:in start' from /home/alok/.rvm/gems/ruby-1.9.3-p385/gems/railties-3.2.19/lib/rails/commands.rb:41:in<top (required)>'
from script/rails:6:in require' from script/rails:6:in

'

I think I am using it in a wrong way, I checked the docs and did not find
anything related to fetching data by Authenticating by service accounts. I
have verified from Google API playground the the access token I used is
valid. Can you guide me as to what am I doing wrong ? Is it possible to do
this via Garb (as I am not using Single User Login anymore as we need
server to server interactions and using Service accounts is the only way.

Thanks,
Alok


Reply to this email directly or view it on GitHub
#40.

┏◇─────────────────
┌─╂ 株式会社 先駈
■━┛ 代表取締役
│ 面川 泰明
│ TEL 03-6271-6858 FAX 03-6850-7117
│ Mail : [email protected]
□────────────────────

from garb.

alokswain avatar alokswain commented on July 28, 2024

The problem is not with OAuth. When I use the access token obtained by using Signet, how do I use that access token in Garb to fetch data from GA ? I think the authentication process is already done as I have a valid Auth Token via Signet.

from garb.

rfernand avatar rfernand commented on July 28, 2024

I have the same problem as you @alokswain. Did you solve the issue?

from garb.

Sija avatar Sija commented on July 28, 2024

@alokswain is your access_token an instance of OAuth2::Client?

from garb.

alokswain avatar alokswain commented on July 28, 2024

@Sija - Thats what I misunderstood. It works when Garb::Session.access_token is an instance of OAuth2::Client instead of a valid access_token. Thanks for the followup. I am closing the issue as I have resolved the problem and pasting the code I used below so that it might help someone in future:

key = Google::APIClient::KeyUtils.load_from_pkcs12("<p12_key_path>", "<p12key pwd>")
client = Google::APIClient.new(application_name: 'Service account demo', application_version: '0.0.1')

service_account = Google::APIClient::JWTAsserter.new(@ga_service_account, 'https://www.googleapis.com/auth/analytics.readonly', 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, expires_in: 1.hour)
Garb::Session.access_token = token

profile = Garb::Management::Profile.all

Edit: Seems this can be directly done using Signet now (untested) and JWTAsserter is deprecated. Please refer Signet gem docs for more details on how to fetch the access token directly using Signet gem.

from garb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.