Get a list of companies using only the user auth_token ?

34 views
Skip to first unread message

Евгений Шевцов

unread,
Mar 20, 2018, 3:39:35 AM3/20/18
to AdWords API Forum
Can I get a list of companies using only the user's OAuth2 token?

Vincent Racaza (AdWords API Team)

unread,
Mar 20, 2018, 4:28:14 AM3/20/18
to AdWords API Forum
Hi,

Could you confirm on what you meant by the list of companies? I have responded to your other forum post but your example code is about getting campaigns and you have an error on it. It seems that this concern is connected to your other forum post.

In regards to using a user's OAuth2 token/credentials, as long as that token has access to the AdWords account, then there is no problem in getting a list of entities via the AdWords API services.

Thanks,
Vincent
AdWords API Team

Евгений Шевцов

unread,
Mar 20, 2018, 4:59:51 AM3/20/18
to AdWords API Forum
Can you show an example using a token without using the property file?

вторник, 20 марта 2018 г., 11:28:14 UTC+3 пользователь Vincent Racaza (AdWords API Team) написал:

Vincent Racaza (AdWords API Team)

unread,
Mar 20, 2018, 6:51:11 AM3/20/18
to AdWords API Forum
Hi,

As you can see in this section, if you don't want to use the property file, then you need to set the OAuth2 fields in the OAuth2TokenBuilder and AdWordsSessionBuilder objects. See sample code snippet below:

$oAuth2Credential = (new OAuth2TokenBuilder())
        //->fromFile()
->withClientId('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
->withClientSecret('XXXXXXXXXXXXXXX')
->withRefreshToken('XXXXXXXXXXXXX')
        ->build();
 
    // Construct an API session configured from a properties file and the OAuth2
    // credentials above.
    $session = (new AdWordsSessionBuilder())
        //->fromFile()
        ->withOAuth2Credential($oAuth2Credential)
->withClientCustomerId('XXX-XXX-XXXX')
->withDeveloperToken('XXXXXXXXXXXXXXXXXX')
        ->build();
 
    self::runExample(new AdWordsServices(), $session);

Евгений Шевцов

unread,
Mar 20, 2018, 7:26:55 AM3/20/18
to AdWords API Forum
And where is the token used here?
I want to extract the OAuth 2.0 upgrade token for each AdWords account that you want to manage.
No MCC

вторник, 20 марта 2018 г., 13:51:11 UTC+3 пользователь Vincent Racaza (AdWords API Team) написал:

Евгений Шевцов

unread,
Mar 20, 2018, 3:18:20 PM3/20/18
to AdWords API Forum
?

вторник, 20 марта 2018 г., 13:51:11 UTC+3 пользователь Vincent Racaza (AdWords API Team) написал:

Vincent Racaza (AdWords API Team)

unread,
Mar 21, 2018, 1:26:36 AM3/21/18
to AdWords API Forum
Hi,

If you are using our client libraries, then the token there is the refresh token (withRefreshToken('XXXX')) which is used to generate the access token in the backend. Before the access token expires or when it expires, the refresh token is used to automatically update it in the backend so you can continue to use the AdWords API services.

Since you are using our PHP client library, then you don't need to worry for the access token's expiration. You only have two options here, either you need to set the OAuth2 credentials in the property file as we recommended or you can set them in your example file as I have provided in my sample code snippet. 
Reply all
Reply to author
Forward
0 new messages