AdWordsUser doesn't have authorization token

155 views
Skip to first unread message

ironside....@gmail.com

unread,
Apr 20, 2018, 1:03:38 PM4/20/18
to AdWords API Forum
Hi. I'm trying to use the TargetingIdeaService with ASP.NET. This is my code so far:

       
 [HttpGet]
       
public IEnumerable<string> Get()
       
{
           
var user = new AdWordsUser();
           
using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201802.TargetingIdeaService))
           
{
               
// Create selector.
               
TargetingIdeaSelector selector = new TargetingIdeaSelector();
                selector
.requestType = RequestType.IDEAS;
                selector
.ideaType = IdeaType.KEYWORD;
                selector
.requestedAttributeTypes = new AttributeType[] {
               
AttributeType.KEYWORD_TEXT,
               
AttributeType.SEARCH_VOLUME,
               
AttributeType.AVERAGE_CPC,
               
AttributeType.COMPETITION,
               
AttributeType.CATEGORY_PRODUCTS_AND_SERVICES
           
};


               
// Set selector paging (required for targeting idea service).
               
var paging = Paging.Default;
               
// Create related to query search parameter.
               
var relatedToQuerySearchParameter = new RelatedToQuerySearchParameter { queries = new String[] { "bakery", "pastries", "birthday cake" } };


               
var searchParameters = new List<SearchParameter> { relatedToQuerySearchParameter };


               
var page = new TargetingIdeaPage();
                page
= targetingIdeaService.get(selector);
               
return new string[] { "value1", "value2" };
           
}
       
}

All looks good until when executing the code throws an invalid_grand error.
During debugging it turned out that the property "authorization_token" of the user object is an empty string. All other credentials come from app.config and are in the object.
I believe I'm missing a step, but I have no idea what the step is.
I'm building a REST API app, so console solutions won't work.

Dhanya Sundararaju (AdWords API Team)

unread,
Apr 20, 2018, 2:52:35 PM4/20/18
to AdWords API Forum
Hi,

The "invalid_grant" error usually indicates that the access or refresh token being passed in your request is incorrect or invalid. 

To verify that your credentials are correct, you can try the CURL request provided below and see if you are able to generate the access tokens. If the credentials are correct, you should get an access token for the below request.

curl https://www.googleapis.com/oauth2/v4/token \
-d refresh_token=your-refresh_token \
-d client_id=your-client-id \
-d client_secret=your-client-secret \
-d grant_type=refresh_token

If your credentials are incorrect and still facing issue then you can generate a new refresh token with the help of this guide and retry your request. Please let me know if the issue persists.

Regards,
Dhanya, AdWords API Team

ironside....@gmail.com

unread,
Apr 21, 2018, 3:43:40 PM4/21/18
to AdWords API Forum
After regenerating the keys, now I'm getting a 

{
 
"error": "unauthorized_client",
 
"error_description": "Unauthorized"
}

Dhanya Sundararaju (AdWords API Team)

unread,
Apr 23, 2018, 12:47:50 PM4/23/18
to AdWords API Forum
Hi,

Do you get this error when you run the curl command that was shared or when you run the client library examples? Could you try opening a new incognito window, then generate the client id and secret using a valid AdWords user login. Also, please make sure you are using the correct scope which is: "https://www.googleapis.com/auth/adwords". After that, please generate the refresh token using the OAuthTokenGenerator.exe. Then, please use those credentials to run GetCampaigns.cs or GetCampaigns.vb and let me know if you still get errors.

ironside....@gmail.com

unread,
Apr 26, 2018, 3:20:12 PM4/26/18
to AdWords API and Google Ads API Forum
The error appeared during the curl command.
So I should generate new OAuth keys, use these, and create the refresh token using the TokenGenerator.exe right?
So far I've been generating refresh tokens using the Google Playground, with the scope provided
If I'm working on localhost should I add the redirect URLs? Or would this work only on a live server?

ironside....@gmail.com

unread,
Apr 26, 2018, 3:41:40 PM4/26/18
to AdWords API and Google Ads API Forum
When I try to use the oauthgenerator.exe it crashes with no error report. I input my credentials and scopes, log in with my account, approve the access, and then the program stops working. Is generating the refresh token using the playground any different?

Dhanya Sundararaju (AdWords API Team)

unread,
Apr 26, 2018, 5:17:48 PM4/26/18
to AdWords API and Google Ads API Forum
Hi,

Using Google Playground sounds good but please make sure that you are choosing type: Web Application and opening in a incognito window while generating the client id and secret. Also, when you follow the steps as mentioned in this section of the guide, could you please let me know which steps show different results in your case, however minor it may seem? Please do make a note of the 'Warnings' in the boxes in that section of the guide.

Having said that, since you are already using the curl, you could try to generate the tokens using that method. This section of the guide lists steps on how to get the tokens using curl command. Once you have the refresh token generated, you could add the credentials and the refresh tokens in your App.config file and try to make the API call.

Please let me know which option you are following as it would be easier to troubleshoot sticking to one method.

Grégory Bittan

unread,
Apr 27, 2018, 3:44:57 PM4/27/18
to AdWords API and Google Ads API Forum
I got the same issue.

OAuthGenerator.exe crashes

Dhanya Sundararaju (AdWords API Team)

unread,
Apr 30, 2018, 11:47:29 AM4/30/18
to AdWords API and Google Ads API Forum
Hi Grégory,

Could you please post on the .NET github as it is a library specific issue? As a workaround, could you please follow the steps as elaborated in this section of the guide to get tokens using the curl command and then try to make the API call after updating in your App.config file? Please let me know if you have further questions.

ironside....@gmail.com

unread,
May 9, 2018, 2:47:42 AM5/9/18
to AdWords API and Google Ads API Forum
Hi Dhanya.
Thank you so much.
It almost works and I feel like I'm almost there. Now I'm getting a "developer token is not approved" error, which is interesting, because my account is a test account, and I copied the developer token.
What is the possible issue here? I already reset the token using incognito tab.

ironside....@gmail.com

unread,
May 9, 2018, 2:52:00 AM5/9/18
to AdWords API and Google Ads API Forum
Ok I realized this is the actual error message: Developer token is not approved for production access, and the customer is attempting to access a production account.
And it makes sense. But how do I make my customer a test user?

Dhanya Sundararaju (AdWords API Team)

unread,
May 9, 2018, 11:10:07 AM5/9/18
to AdWords API and Google Ads API Forum
Hi,

You will need to create a Test manager account and then create test client accounts. All client accounts created under the test manager account will be automatically marked as test accounts. Please refer this section of guide for the steps and let me know if you have any further questions.

ironside....@gmail.com

unread,
May 10, 2018, 10:01:43 AM5/10/18
to AdWords API and Google Ads API Forum
Now I'm just really confused. I created new "test" accounts using this link: https://adwords.google.com/um/Welcome/Home?a=1&sf=mt&authuser=0#ta, but how am I supposed to log into these accounts to create the OAuth test credentials? This is what it looks like:

The "test" is the name of the account set by me. They are not test accounts, there is supposed to be a red label somewhere according to this: https://developers.google.com/adwords/api/docs/guides/accounts-overview#test_accounts There is an image below. I cannot see anything like this anywhere. What am I missing?
Untitled.png

Teja Makani

unread,
May 10, 2018, 4:07:01 PM5/10/18
to AdWords API and Google Ads API Forum
Hello Ironside,

The accounts named as test are AdWords test manager accounts. You could switch back to old UI view to see that there is a red banner for these accounts (clicking on the return to previous AdWords ICS under the Tools, Billing and settings icon). To create the oAuth credentials required to make the API call, you can follow the steps listed in this guide. You have to make sure that the call is being authorized by the user who has access to the accounts. Please let me know if you face any issues. 

Regards,
Sai Teja, AdWords API Team.

ironside....@gmail.com

unread,
May 11, 2018, 5:10:29 AM5/11/18
to AdWords API and Google Ads API Forum
Ok so I have the test account and the manager account. The manager is the default non-test account. When I try to create the oauth credentials, they are created with the manager (non-test) account. I need to use the test account to create the oauth credentials. How can I do that?

ironside....@gmail.com

unread,
May 11, 2018, 5:33:35 AM5/11/18
to AdWords API and Google Ads API Forum
OK I think I got through it. I used the client id for the test account. Now I'm getting this error:
{Error returned when the requested <a href='Paging'>Paging</a> is missing from the <a href='TargetingIdeaSelector'>TargetingIdeaSelector</a> when required.. (Error: TargetingIdeaError.NO_PAGING_IN_SELECTOR, FieldPath: selector, Trigger: )
Error returned when the <a href='TargetingIdeaSelector'>TargetingIdeaSelector</a> doesn't have enough <a href='SearchParameter'>SearchParameter</a>s to execute request.. (Error: TargetingIdeaError.INSUFFICIENT_SEARCH_PARAMETERS, FieldPath: selector.searchParameters, Trigger: )
Missing required field.. (Error: RequiredError.REQUIRED, FieldPath: selector.paging, Trigger: )}

And this is my code:
    // GET: api/<controller>
    [HttpGet]
    public IEnumerable<string> Get()
    {
        var user = new AdWordsUser();
        using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201802.TargetingIdeaService))
        {
            // Create selector.
            TargetingIdeaSelector selector = new TargetingIdeaSelector();
            selector.requestType = RequestType.IDEAS;
            selector.ideaType = IdeaType.KEYWORD;
            selector.requestedAttributeTypes = new AttributeType[] {
            AttributeType.KEYWORD_TEXT,
            AttributeType.SEARCH_VOLUME,
            AttributeType.AVERAGE_CPC,
            AttributeType.COMPETITION,
            AttributeType.CATEGORY_PRODUCTS_AND_SERVICES
        };

            // Set selector paging (required for targeting idea service).
            var paging = Paging.Default;
            // Create related to query search parameter.
            var relatedToQuerySearchParameter = new RelatedToQuerySearchParameter { queries = new String[] { "bakery", "pastries", "birthday cake" } };

            var searchParameters = new List<SearchParameter> { relatedToQuerySearchParameter };

            var page = new TargetingIdeaPage();
            page = targetingIdeaService.get(selector);
            return new string[] { "value1", "value2" };
        }
    }

The paging thing is there, so I have no idea what I'm missing

W dniu czwartek, 10 maja 2018 22:07:01 UTC+2 użytkownik Teja Makani napisał:

ironside....@gmail.com

unread,
May 11, 2018, 7:44:45 AM5/11/18
to AdWords API and Google Ads API Forum
I'll open another thread with further questions. This question was solved with creating the oauth credentials in incognito window.
Reply all
Reply to author
Forward
0 new messages