Coder Social home page Coder Social logo

Comments (5)

TigerWolf avatar TigerWolf commented on July 1, 2024

You should try to use the authorize method on api instead.

Try @api.authorize({:oauth2_token => access_token})

On Sun, Dec 22, 2013 at 3:36 AM, Joan.R [email protected] wrote:

I have the following situation:

First time the User gives my application permition to access its Adwords
account, I store the following in my DB:

access_token, refresh_token, expires_in, issued_at

Later, when I want to do an API call, I get those values from the current
user, and do the following:

@api = AdwordsApi::Api.new(config_filename)
token = {:access_token => current_user.access_token, :refresh_token =>
current_user.refresh_token, :expires_in => current_user.adwords_expires_in,
:issued_at => current_user.adwords_issued_at, :id_token => nil }
credentials = @api.credential_handler()
credentials.set_credential(:oauth2_token, token)
credentials.set_credential(:client_customer_id, selected_account)

However, it seems that when that access_token has expired, I get a OAUTH
INVALID TOKEN error.

Isn't this the correct way of doing offline access? What am I missing
here? I am also guessing that if I do it this way, I would never be
updating the access_token with the new access_token that I got from the
refresh_token, so I am wondering what would be the correct way to do so?

PD: It would be nice if you could tell the people that manage the API
Adwords forum to check for new users and accept/approval their messages ;)


Reply to this email directly or view it on GitHubhttps://github.com//issues/13
.

from google-api-ads-ruby.

novito avatar novito commented on July 1, 2024

If I do:

@api.authorize({:oauth2_token => access_token})

Where access_token is the Hash with token and refresh token, I keep getting OAUTH_TOKEN_INVALID when trying to hit the API. Actually this @api.authorize({:oauth2_token => access_token}) returns the same Hash that I currently have, so I guess it's not working as expected (is not getting a new token from the endpoint).

from google-api-ads-ruby.

TigerWolf avatar TigerWolf commented on July 1, 2024

Try modifying the hash and setting the issued_at to yesterday.

On Mon, Dec 23, 2013 at 3:28 AM, Joan.R [email protected] wrote:

If I do:

@api.authorize({:oauth2_token => access_token})

Where access_token is the Hash with token and refresh token, I keep
getting OAUTH_TOKEN_INVALID when trying to hit the API. Actually this @api.authorize({:oauth2_token
=> access_token}) returns the same Hash that I currently have, so I guess
it's not working as expected.


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-31091053
.

from google-api-ads-ruby.

novito avatar novito commented on July 1, 2024

TigerWolf, thanks for your suggestion. Have you tried this with the Rails example provided in the library?

Because I keep getting the same thing. When I do:

returned_token = @api.authorize(:oauth2_token => token, :client_customer_id => selected_account)

Where token is:
{:access_token=>"xxxxxxxxxxxxxx", :refresh_token=>"xxxxxxxxxxxxxxxxxx", :issued_at=>Sun, 22 Dec 2013 23:29:33 UTC +00:00, :expires_in=>3600, :id_token=>nil}

If I do @api.inspect, right after the authorize call I get:

#<AdwordsApi::Api:0xbc2e074 @wrappers={}, @config=#<AdsCommon::Config:0xbc2e04c @config={:authentication=>{:method=>:OAUTH2, :oauth2_client_id=>"xxxxx", :oauth2_client_secret=>"xxxxx", :developer_token=>"xxxxx", :user_agent=>"rails", :oauth2_token=>{:access_token=>"xxxxx", :refresh_token=>"xxxxx", :issued_at=>Sun, 22 Dec 2013 23:29:33 UTC +00:00, :expires_in=>3600, :id_token=>nil}, :client_customer_id=>"121212"}, :service=>{:environment=>:PRODUCTION}, :connection=>{:enable_gzip=>false}, :library=>{:log_level=>"INFO", :logger=>#<Logger:0xbc3692c @progname=nil, @level=1, @default_formatter=#<Logger::Formatter:0xbc36954 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0xbc36a1c @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0xbc36a30 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0xbc37034>>>>}}>, @logger=#<Logger:0xbc3692c @progname=nil, @level=1, @default_formatter=#<Logger::Formatter:0xbc36954 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0xbc36a1c @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0xbc36a30 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0xbc37034>>>>, @credential_handler=#<AdwordsApi::CredentialHandler:0xbc37200 @config=#<AdsCommon::Config:0xbc2e04c @config={:authentication=>{:method=>:OAUTH2, :oauth2_client_id=>"xxxxx", :oauth2_client_secret=>"xxxxxxxP", :developer_token=>"xxxxxxxxxxxxxxxx", :user_agent=>"rails", :oauth2_token=>{:access_token=>"xxxxxxxxxxxxxx", :refresh_token=>"xxxxxxxxxxx", :issued_at=>Sun, 22 Dec 2013 23:29:33 UTC +00:00, :expires_in=>3600, :id_token=>nil}, :client_customer_id=>"121212"}
But when trying to use the @api object to do an API call, I keep getting:

Exception occurred: AdwordsApi::V201309::CampaignService::ApiException
[AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'']

I should add that I have in the config file oauth2_access_type: 'offline'

from google-api-ads-ruby.

novito avatar novito commented on July 1, 2024

Closing. I was having a misspelling in one of my Models that was avoiding refreshing the token.

from google-api-ads-ruby.

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.