Adwords PHP API

51 views
Skip to first unread message

John Mark

unread,
Mar 11, 2016, 8:57:05 AM3/11/16
to AdWords API Forum
After endless problems with the API, I have got to the stage where I can;

1. Get the authorisation URL and have the user accept access.
2. Retrieve the authorisation code.
3. Use auth code to get refresh token + access token.
4. Access the data using the GetCampaigns method.

However, once this first token expires, I can't seem to get a new access token.

The code below is the current one I am testing;

require_once dirname(__FILE__) . '/init.php';

$user = new AdWordsUser();

$OAuth2Handler = $user->GetOAuth2Handler();
$user->RefreshAccessToken($user->GetOAuth2Info());

which results in the following error;
Uncaught SoapFault exception: [soap:Server] [AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:''] in /usr/www/users/dragorefcc/api/AdWords/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php:216 Stack trace: #0 /usr/www/users/dragorefcc/api/AdWords/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php(216): SoapClient->__soapCall('get', Array, NULL, Array, Array) #1 /usr/www/users/dragorefcc/api/AdWords/src/Google/Api/Ads/AdWords/v201601/CampaignService.php(7902): AdsSoapClient->__soapCall('get', Array) #2 /usr/www/users/dragorefcc/advertising/getCampaigns.php(15): CampaignService->get(Object(Selector)) #3 /usr/www/users/dragorefcc/advertising/index.php(61): include('/usr/www/users/...') #4 {main} thrown in /usr/www/users/dragorefcc/api/AdWords/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php on line 216

Yin Niu

unread,
Mar 11, 2016, 9:37:11 AM3/11/16
to AdWords API Forum
Hello,

Once access token is expired, you can use refresh token to refresh an access token. By default, the client libraries automatically refresh access token. Please check out the PHP examples

Thanks,
Yin, AdWords API Team. 
Reply all
Reply to author
Forward
0 new messages