Error when calling set credentials from sample Rails App

112 views
Skip to first unread message

Jeffrey Lee

unread,
Jul 14, 2015, 6:07:36 AM7/14/15
to adwor...@googlegroups.com

So I downloaded the sample rails app here: https://developers.google.com/adwords/api/docs/clientlibraries

I got it running, but when I click on the List Accounts link I get this stack trace:


NoMethodError - undefined method `[]=' for nil:NilClass:

  google-ads-common (0.9.9) lib/ads_common/credential_handler.rb:65:in `set_credential'

  app/controllers/application_controller.rb:50:in `create_adwords_api'

  app/controllers/application_controller.rb:36:in `get_adwords_api'

  app/controllers/account_controller.rb:18:in `get_accounts_graph'

  app/controllers/account_controller.rb:5:in `index'


I have my developer_token, client_customer_id, oauth2_client_id, and oauth2_client_secret. I don't know why I am getting this issue. Does anyone have any ideas? Everything in my token had a value except the id_token key.

Jeffrey Lee

unread,
Jul 14, 2015, 3:09:51 PM7/14/15
to adwor...@googlegroups.com
Update: I try to play around with the API again this morning. I have no idea what has changed, but I can't even start up the server now. While trying to fix my initial bug, I wanted to do a fresh start. So I logged out on the app and now I get a 

NoMethodError - undefined method `[]=' for nil:NilClass:

  google-ads-common (0.9.9) lib/ads_common/credential_handler.rb:65:in `set_credential'

  google-ads-common (0.9.9) lib/ads_common/api.rb:102:in `block in authorize'

  google-ads-common (0.9.9) lib/ads_common/api.rb:101:in `authorize'

  app/controllers/login_controller.rb:15:in `prompt'


The difference this time is that it is coming from the login_controller. It seems that "token = api.authorize({:oauth2_callback => login_callback_url})" is failing on me and I don't know why. The credentials on the adwords_api.yml file didn't change. I did refresh the credentials afterwards on the developer console and try to put the updated keys in the yml file, but that didn't solve the issue either. How the app is just simply broken for me.

Jeffrey Lee

unread,
Jul 14, 2015, 5:04:17 PM7/14/15
to adwor...@googlegroups.com
Ignore my last post, I got that figured out. But I am still running into my initial problem with the List Account link


On Tuesday, July 14, 2015 at 3:07:36 AM UTC-7, Jeffrey Lee wrote:

Jeffrey Lee

unread,
Jul 14, 2015, 6:18:28 PM7/14/15
to adwor...@googlegroups.com
As an update, it turns out that maybe what I want isn't in the List Accounts link. I am trying to get the Retrieve a Report page to work. When I click the "get report" button, I get this error now:

"An error occurred during report retrieval:
HTTP code: 400, error type: 'AuthenticationError.NOT_ADS_USER', trigger: '<null>', field path: ''

At first I thought it was because I was using an account that wasn't tied to an adwords account, but the error still appeared when I set up the credentials with a gmail account that tied to an adwords account.


On Tuesday, July 14, 2015 at 3:07:36 AM UTC-7, Jeffrey Lee wrote:

Jeffrey Lee

unread,
Jul 14, 2015, 8:54:46 PM7/14/15
to adwor...@googlegroups.com
I realize that for this sample Rails app, when I click "Proceed" at the home page, it asks me to login with my Gmail account. I know this will sound silly, but I thought the account doesn't matter. It turns out when I logged in with a Gmail account that has a production MCC account, the error goes away, although I get a different error now instead. I get:

ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH

I then read that the account I selected can't be a production MCC ID, which makes sense because the link says "Enter Test Account ID". However after I created my MCC Test Account, using an email that isn't tied to the production MCC account, I try to retrieve a report again and I get this now: 

AuthorizationError.USER_PERMISSION_DENIED

Can anyone help me out and tell me what I am doing wrong. To reiterate, with this sample rails app, I am logged in using the gmail account associated with the production MCC account. The account ID I entered in after clicking the "Enter Test Account ID" is the ID from the test MCC account. My oauth2_client_id, oauth2_client_secret, and developer_token are created by the gmail account associated with the production MCC account and assigned in the adwords_api.yml file as so. The client_customer_id in the adwords_api.yml file is assigned to the customer id of the production MCC account. I have also bumped the google-adwords-api gem's version to 0.15.2. 

Is there something wrong with my set up? I just want to generate a report. I don't need it automated. I just want to generate it this one time only.

On Tuesday, July 14, 2015 at 3:07:36 AM UTC-7, Jeffrey Lee wrote:

Danial Klimkin

unread,
Jul 15, 2015, 7:18:07 AM7/15/15
to adwor...@googlegroups.com, leejef...@gmail.com
Hello Jeffrey,


Let's go over every error you've encountered:

AuthenticationError.NOT_ADS_USER means you've authorized with a non-AdWords account. E.g. your private gmail account that don't have AdWords account created.
ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH means you are trying to run a report against an MCC account. Reports can only be executed against advertiser (non-MCC) accounts.
AuthorizationError.USER_PERMISSION_DENIED means your OAuth credentials don't match clientCustomerId you specify. Basically, login you are using doesn't have access to the account you are trying to touch.

BTW, this is covered here:


So, for your case you need to re-do the OAuth flow (generate new refresh token) making sure you are logged in under a proper account. This should be either you production MCC login (for prod) or test MCC login (for test). Next, set clientCustomerId to the target non-MCC account. This account needs to be either under prod or test MCC (make sure it matches to what you've authorized with).


-Danial, AdWords API Team.

Jeffrey Lee

unread,
Jul 15, 2015, 1:15:12 PM7/15/15
to adwor...@googlegroups.com, leejef...@gmail.com
I am confused as to your last line where you said "Next, set clientCustomerId to the target non-MCC account. This account needs to be either under prod or test MCC (make sure it matches to what you've authorized with)." You said to set the client_customer_id to a non-MCC account, but that account needs to be a prod/test MCC account?

Jeffrey Lee

unread,
Jul 15, 2015, 1:44:36 PM7/15/15
to adwor...@googlegroups.com, leejef...@gmail.com
Also thank you for verifying the errors. I saw the common errors page, but I wasn't completely sure. But still, knowing this, what is wrong with the set up I specified above? The last error I had was the USER_PERMISSION_DENIED. You are saying my OAuth credentials don't match my client_customer_id, but I created the OAuth client_id and client_secret using the production MCC account and the client_customer_id is the customer ID of that MCC account. All this is stored in my yml file.

So my yml file for this sample app has my production MCC credentials such as client_customer_id, oauth2_client_id, oauth2_client_secret and developer_token. In the app, I logged in with the gmail account associated with the that production MCC account. I clicked on the "Enter Test Account ID" link to get to a page to put in a test account ID. So I created a test MCC account and use the client_customer_id there. Not sure why I need this step, but it seems like this sample app needs an active account. I could be wrong, let me know if I am.


On Wednesday, July 15, 2015 at 4:18:07 AM UTC-7, Danial Klimkin wrote:

Jeffrey Lee

unread,
Jul 15, 2015, 2:42:36 PM7/15/15
to adwor...@googlegroups.com, leejef...@gmail.com
You can ignore my previous posts. I think what I got mixed up in was that MCC and my Adwords Advertising account were the same thing. I realize that my client_customer_id probably should be the id in my Adwords Advertising account. I am able to generate "Keyword Performance" reports sometimes. When I am able to create the report, the report is empty. Other times, depending on what field I inputed, it seems to load on forever and then, I get a 502 error. 


On Wednesday, July 15, 2015 at 4:18:07 AM UTC-7, Danial Klimkin wrote:

Jeffrey Lee

unread,
Jul 15, 2015, 8:42:04 PM7/15/15
to adwor...@googlegroups.com
Hi, I finally got everything working. Thanks Danial to pointing me to the right path.


On Tuesday, July 14, 2015 at 3:07:36 AM UTC-7, Jeffrey Lee wrote:
Reply all
Reply to author
Forward
0 new messages