[AuthenticationError.OAUTH_TOKEN_INVALID

641 views
Skip to first unread message

Abhishek Dutt

unread,
Jun 1, 2015, 8:44:02 AM6/1/15
to adwor...@googlegroups.com, Abhishek Dutt
Hi,

I have been  working on Google Adword API and am using PHP client sdk to request the SOAP call.
I have gone through the basic setup process.
I have created a Production MCC account and got a developer  Token from there which is pending from an email address.
So to test i created another Test MCC account using another email account.
From this test MCC account , i created a test adword account which itself by default got linked, this got me my clientCustomerId
Now to get client id and client secret , I used the google console to create a project and create the client id. I used  Web Application Type to create the client id and put the redirection url to https://developers.google.com/oauthplayground
In the playground , i specified  client id , secret key in the setting and then the scope https://www.googleapis.com/auth/adwords to authorize, which got me the authorization code which then i exchanged to get referesh token  and access token.
Now when i use them in my file , till the time i access the user object , i get everything , but lets suppose i want to get a list of campaign then it shows the following error :

Fatal error: Uncaught SoapFault exception: [soap:Server] [AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'<null>'] in C:\wamp\www\googleAdwords\lib\Google\Api\Ads\Common\Lib\AdsSoapClient.php:231 Stack trace: #0 C:\wamp\www\googleAdwords\lib\Google\Api\Ads\Common\Lib\AdsSoapClient.php(231): SoapClient->__soapCall('get', Array, NULL, Array, Array) #1 C:\wamp\www\googleAdwords\lib\Google\Api\Ads\AdWords\v201409\CampaignService.php(7777): AdsSoapClient->__soapCall('get', Array) #2 C:\wamp\www\googleAdwords\campaign.php(60): CampaignService->get(Object(Selector)) #3 {main} thrown in C:\wamp\www\googleAdwords\lib\Google\Api\Ads\Common\Lib\AdsSoapClient.php on line 231

Meanwhile , here is the code , with keys removed

<?php

$path = dirname(__FILE__) . '/lib';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once dirname(__FILE__) . '/lib/Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
require_once dirname(__FILE__) . '/lib/Google/Api/Ads/AdWords/Util/ReportUtils.php';


define("OAUTH_CLIENT_ID", "[****]");
define("OAUTH_CLIENT_SECRET", "[****]");
define("OAUTH_ACCESS_TOKEN", "[****]");
define("OAUTH_REFRESH_TOKEN", "[*****]");
define("CUSTOMER_ACCOUNT_ID", "[*****]");
define("DEVELOPER_TOKEN", "[****]");
define("API_VERSION", "v201409");
 
$user = new AdWordsUser();
$user->SetDeveloperToken(DEVELOPER_TOKEN);
$user->SetClientCustomerId(CUSTOMER_ACCOUNT_ID);

print_r($user); 

$user->SetOAuth2Info(array(
    "client_id" => OAUTH_CLIENT_ID,
    "client_secret" => OAUTH_CLIENT_SECRET,
    "access_token" => OAUTH_ACCESS_TOKEN,
    "refresh_token" => OAUTH_REFRESH_TOKEN
));
 
$user->LoadService('ReportDefinitionService', API_VERSION);
 
print_r($user);



// Get a list of campaigns
$campaignService = $user->GetService('CampaignService', API_VERSION);
$selector = new Selector();
$selector->fields = array('Id', 'Name');
$campaigns = $campaignService->get($selector);
 
print_r($campaigns);


?>


Please help me out !
I am not able to find a way out

Thanks
Abhishek Dutt

Thanet Knack Praneenararat (AdWords API Team)

unread,
Jun 2, 2015, 2:53:14 AM6/2/15
to adwor...@googlegroups.com, abhishek...@gmail.com, abhishek...@gmail.com
Hi,

It seems you have problems with SOAP authentication.
I highly recommend you to use our client library, which is also available in PHP as well.

Could you please try that first and see if you can get through it? 
You can easily fill in your credential information in auth.ini (in case of PHP), hence there is no need to tweak your $user variable.

By the way, you need not to fill in an access token, as a refresh token required in auth.ini will be used to generate new access tokens when needed.
Using our client libraries should help you bypass these overheads of SOAP authentication.

You can find more information about how to setup the PHP client library here.

Best Regards,
Thanet, AdWrods API Team

pappu chauhan

unread,
Apr 7, 2017, 12:41:14 PM4/7/17
to AdWords API Forum, abhishek...@gmail.com
Fatal error: Uncaught exception 'Google\AdsApi\AdWords\v201702\cm\ApiException' with message '[AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'<null>']' 

Shwetha Vastrad (AdWords API Team)

unread,
Apr 12, 2017, 10:31:25 AM4/12/17
to AdWords API Forum, abhishek...@gmail.com
Hi, 

This error occurs when the access token passed in the HTTP header was incorrect. Could you check if you are using the correct OAuth2 credentials associated with your account? Could you describe the steps you took to get your OAuth2 credentials and refresh token? Please try generating a new refresh token and see if it solves the issue. 

Regards,
Shwetha, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages