0
votes

Let me start here. The Google Adwords API does not work with the standard Google API Oauth method. It has it's own. Please do not respond with using that library or it's methods it is different.

OK, over the last couple days I have been integrating the GoogleAdwords API OAuth method code into my companies code. I can get an access and refresh token from the server with no issue. The access tokens are good for 1 hours and then need to be refreshed.

// oauth 2 config
$credentials= array(
    'client_id' => $config['id'],
    'client_secret' => $config['secret'],
    'access_token' => $params['access_token'],
    'refresh_token' => $params['refresh_token']
);

$user = new \AdWordsUser(null, $adwords['dev_token'],
    $adwords['useragent'], null, null, $credentials);

The above code works properly with a brand new token. If I take the $user object and try to get CustomerService object from the API I can get the data back. However after an hour the token goes bad and I am no longer able to use it.

I have searched Google's Adwords API Forum (via Google Groups), and also a general Google search. The only code I have been able to find is this code.

$client = $user->GetOAuth2Handler();
$credentials = $client->RefreshAccessToken($user->GetOAuth2Info());
$user->SetOAuth2Info($credentials);

But when I add it I always get this error.

{ "error" : "unauthorized_client" }

I am at a complete loss...

Also please not I do not use an auth.ini we use our own config files and add the parameters to the api objects.

1
Have you taken a look at the code provided by google for this particular task?Ohgodwhy
That code is to "GET" a refresh token, not to use it to refresh the access token. I've already sorted ot the problem will answer my own question.thenetimp

1 Answers

0
votes
{ "error" : "unauthorized_client" }

This error means that a different google application client_id was specified. We use multiple google apps and I had copied and pasted some code forgetting that for Adwords we are using a new app, where other google APIs we integrate are all using the same app.