Not able to authenticate when testing adwords_on_rails example on my system

14 views
Skip to first unread message

Arjun Rajkumar

unread,
Mar 29, 2017, 5:14:33 AM3/29/17
to AdWords API Forum
Hi, 

Just looking to learn more about the Adwords API, and thought i'll test the adwords_on_rails example on my local system. 

The example always starts by authenticating a user if a user is not signed in. 

# Checks if we have a valid credentials.
  def authenticate()
    token = session[:token]
    redirect_to login_prompt_path if token.nil?
    return !token.nil?
  end


Over here as the session[:token] is nil - it redirects to the login_prompt_path

This is the code for that 

def prompt()
    api = get_adwords_api()
    if session[:token]
      redirect_to home_index_path
    else
      begin
        token = api.authorize({:oauth2_callback => login_callback_url})
      rescue AdsCommon::Errors::OAuth2VerificationRequired => e
        @login_url = e.oauth_url
      end
    end
  end

Over here it authorises the api and gets the token details. 

From my app - these are the details.

token:

pry(#<LoginController>)> token

=> {:access_token=>"ya29.GlwdBFmXLFG6N4LZcXYZXXYZXYZsI3w2TO7S2AT8jxg2H5M9fZK8w",

 :refresh_token=>"1/MRi81Wp0D0XYZXXYZXYZsSsioOgHxas",

 :issued_at=>2017-03-29 09:11:29 +0530,

 :expires_in=>3600,

 :id_token=>nil}


[2] pry(#<LoginController>)> @login_url

=> nil


Then in the view for login_prompt_path - it says this. 

<p>Please authorize with a google account first:</p>
<p><a href="<%= @login_url %>">Proceed</a></p>


I understand that I need to click on Proceed so that I can select an Adwords account for this example.
However, my @login_url is always nil - so the clicking on Proceed - does nothing. 

Can someone please help me solve this. I seem to be doing something wrong - but have copied this code from the example. 

Would really help to get some answers to this. Thanks for your time.

Arjun


Arjun Rajkumar

unread,
Mar 29, 2017, 8:54:29 AM3/29/17
to AdWords API Forum
Still stuck on this - basically the <p><a href="<%= @login_url %>">Proceed</a></p>  on the login_prompt_path is nil - and hence clicking on this does not take a uesr anywhere. 

Any suggestions?

Thanks

Arjun

Shwetha Vastrad (AdWords API Team)

unread,
Mar 29, 2017, 3:29:03 PM3/29/17
to AdWords API Forum
Hi Arjun, 

Could you let me know what type of OAuth2 credentials you are using? Could you also confirm that you followed the instructions provided here to set up the Rails application? Since this is specific to the Ruby client library, I suggest that you create an issue in the library's repository as well. 

Regards,
Shwetha, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages