Managing Accounts - Migration from Adwords API to Google Ads API

118 views
Skip to first unread message

Tomas Guerra

unread,
Jan 25, 2022, 2:33:15 PM1/25/22
to Google Ads API and AdWords API Forum
Hello!
I'm currently working on the migration of a service that uses google Adwords API. I need to migrate from this API to Google Ads API, because the first one is being deprecated.

We have many clients with their Google Ads accounts and we get their corresponding refresh tokens with their consent to make operations (oauth). Using the Java SDK, when we need to make a request on behalf of our clients Google Ads account, we instanciate a session according to this code:

API_CONFIG = (
   {OUR_CLIENT_REFRESH_TOKEN},     //This changes with different client accounts
    {APP_CLIENT_ID},
    {APP_CLIENT_SECRET},
    {CLIENT_GOOGLE_ADS_ACCOUNT_ID},   //This changes with different client accounts
    {USER_AGENT},
    {DEVELOPER_TOKEN}
);

// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential =
new OfflineCredentials.Builder()
.forApi(OfflineCredentials.Api.ADWORDS)
.from(API_CONFIG)
.build()
.generateCredential();

// Construct an AdWordsSession.
session = new AdWordsSession.Builder().from(API_CONFIG).withOAuth2Credential(oAuth2Credential).build();

But with the new API (Google Ads API) I could not find how to replicate this. I mean, using the oauth credentials generated from an account's refresh token.

Is it possible to do the same thing with Google Ads API? I came across this code snippet on the account management section of the docs

// Optional: Change credentials to use a different refresh token, to retrieve customers
  //           available for a specific user.
  //
  // UserCredentials credentials =
  //     UserCredentials.newBuilder()
  //         .setClientId("INSERT_OAUTH_CLIENT_ID")
  //         .setClientSecret("INSERT_OAUTH_CLIENT_SECRET")
  //         .setRefreshToken("INSERT_REFRESH_TOKEN")
  //         .build();
  //
  // client = client.toBuilder().setCredentials(credentials).build();


Apparently, this seems to be doing the same trick, but it is stated that few requests can be done with this setting. I tried getting the user_list of an account and I'm getting a PERMISSION_DENIED error.

I understand that to achieve this with the Google Ads API I need to have our client's accounts linked to our Manager account. Doing that works alright. But the question is, is it possible to do it the Adwords API way? Using our client's account refresh tokens?

Thanks in advance for your help!
Message has been deleted

Google Ads API Forum Advisor

unread,
Jan 25, 2022, 10:20:48 PM1/25/22
to tomasgu...@gmail.com, adwor...@googlegroups.com
Hi Tomas,

Thank you for posting your concern and providing updates to it.

I can see that you've already addressed the error that you encountered. However, this is how you will set the customer ID in the request header of the Google Ads API, you will need to set the customer ID of the Google Ads account, where your login user account has direct access, to the login-customer-id field. Then, generate Oauth2 credentials using this login user account and apply it in your Google Ads API environment. Also, the Google Ads account where you want to generate or mutate should have a link to the Google Ads account where you have direct access.

Let me know if you have further questions and our team will be happy to provide support here.

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2VPSZy:ref

Tomas Guerra

unread,
Jan 26, 2022, 6:56:54 AM1/26/22
to Google Ads API and AdWords API Forum

Thanks a lot for your help!
So, it is not possible to manage multiple unrelated Google Ads accounts with the Google Ads API? Even if I get the refresh tokens with the consent of the account owners?

Google Ads API Forum Advisor

unread,
Jan 26, 2022, 1:50:40 PM1/26/22
to tomasgu...@gmail.com, adwor...@googlegroups.com
Hi Tomas,

It is possible to manager multiple unrelated accounts, but you will have to change the login customer ID in accordance with the account that you are targeting (or simply change the targeted customer ID if you are authenticating directly with the client account). You can read more about the login customer ID header here.

Regards,
Matt
Google Ads API Team

Google Logo
Matt
Google Ads API Team
 


ref:_00D1U1174p._5004Q2VPSZy:ref
Reply all
Reply to author
Forward
0 new messages