aarryy
aarryy

Reputation: 502

Cannot make GetRefreshToken.php work with Adwords API

I'm a noob to Adwords API and please let me know if I 'm not describing my issue clearly. I searched on the internet, people do have similar issue as I do yet none of them gave a solution that worked for me. I pretty much have the same problem as the OP of this thread does. The only difference is I was working on the test account (the developer token of the live MCC account is pending). In the auth.ini, I've had the following information set,

developerToken = "PENDING_DEVELOPER_TOKEN_OF_THE_LIVE_ACCOUNT"
userAgent = "COMPANY_NAME"
clientCustomerId = "CUSTOMER_ID_OF_TEST_ACCOUNT"

client_id = "CLIENT_ID_OF_TEST_ACCOUNT"
client_secret = "CLIENT_SECRET_OF_TEST_ACCOUNT"

All other info are left as default.

I followed this tutorial to get the client id and the client secret. And that pair of id and secret is associated with the test account as I was logged in the test account email when I registered the app in Google Cloud Console. I also tested with the live MCC account and generated another pair of id and secret, yet neither of them worked. When I run the GetRefreshToken.php in the browser, I got the error message as below:

Your OAuth2 Credentials are incorrect. Please see the GetRefreshToken.php example. { "error" : "invalid_request" }

I've been banging my head against the desk for the entire day, still cannot figure out what I've done wrong with the configuration. Any insight is appreciated. Many thanks!

Upvotes: 1

Views: 2614

Answers (1)

depz123
depz123

Reputation: 507

These are the steps to set up the adwords api:

  1. Download the client library (https://github.com/googleads/googleads-php-lib)

  2. Register your app in the live MCC account. Log into https://cloud.google.com/console. Under Api's & auth -> credentials , click 'Create new client id' and make sure you select the 'installed application option'. Redirect uri will automatically point to your localhost. So make sure you are running your app in localhost

  3. Now create a test MCC account.

  4. Inside your test MCC account , click on 'Create Acccount'. Inside the create account form there is an option to invite an user. Enter the email address for your test account here. Note that this account should not already be associated with an adwords account.

  5. Once you accept the invitation and everything, your test account will be linked to your test MCC account. It will be displayed in a table in your MCC test account dashboard.

  6. In the auth.ini file , use the developer token, client id and client secret from your live account. The clientCustomerId should be the id of your test account.

  7. Now run the GetRefreshToken.php file from the command line. Copy and paste the output url in your browser. Then log in to your test account. You will be asked to accept the permission for your app to access the adwords account.

  8. Once you accept, you will be redirected to your app and the url will have a 'code' parameter.

  9. Copy and paste the code back in your command line where it will ask for the authorization code. Your refresh token will be displayed.

Upvotes: 4

Related Questions