AuthenticationError.OAUTH_TOKEN_INVALID while accessing AdWord API

2,708 views
Skip to first unread message

Sandeep Gupta

unread,
Apr 16, 2014, 7:45:15 AM4/16/14
to adwor...@googlegroups.com
HI This is Sandeep here, i am trying to integrate Google Adword API to utilize it better way, but i am getting below error.
faultString: [AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'<null>']


i have generated CLient ID, Client secret and Refresh token and added these values in ads.properties.

But i am getting error on below steps.

Selector selector = builder
        .fields("Id", "Name")
        .orderAscBy("Name")
        .offset(offset)
        .limit(PAGE_SIZE)
        .build();
CampaignPage page = campaignService.get(selector); // this step is giving error.


ERROR DETAILS ::

pr 16, 2014 5:01:15 PM org.apache.axis.utils.JavaUtils isAttachmentSupported
WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
Exception in thread "main" AxisFault
 faultSubcode: 
 faultString: [AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'<null>']
 faultActor: 
 faultNode: 
 faultDetail: 
{https://adwords.google.com/api/adwords/cm/v201402}ApiExceptionFault:<message>[AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'&lt;null&gt;']</message><ApplicationException.Type>ApiException</ApplicationException.Type><errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AuthenticationError"><fieldPath/><trigger>&lt;null&gt;</trigger><errorString>AuthenticationError.OAUTH_TOKEN_INVALID</errorString><ApiError.Type>AuthenticationError</ApiError.Type><reason>OAUTH_TOKEN_INVALID</reason></errors>

[AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'<null>']
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:104)
at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:90)
at com.google.api.ads.adwords.axis.v201402.cm.ApiException.getDeserializer(ApiException.java:143)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.axis.encoding.ser.BaseDeserializerFactory.getSpecialized(BaseDeserializerFactory.java:154)
at org.apache.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(BaseDeserializerFactory.java:84)
at org.apache.axis.encoding.DeserializationContext.getDeserializer(DeserializationContext.java:464)
at org.apache.axis.encoding.DeserializationContext.getDeserializerForType(DeserializationContext.java:547)
at org.apache.axis.message.SOAPFaultDetailsBuilder.onStartChild(SOAPFaultDetailsBuilder.java:157)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.google.api.ads.adwords.axis.v201402.cm.BudgetServiceSoapBindingStub.mutate(BudgetServiceSoapBindingStub.java:795)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.api.ads.common.lib.soap.SoapClientHandler.invoke(SoapClientHandler.java:109)
at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:201)
at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:64)
at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:93)
at $Proxy15.mutate(Unknown Source)
at com.homeshop18.adword.basic.GetCampaigns.runExample(GetCampaigns.java:107)
at com.homeshop18.adword.basic.GetCampaigns.main(GetCampaigns.java:71)


Josh Radcliff (AdWords API Team)

unread,
Apr 17, 2014, 10:48:00 AM4/17/14
to adwor...@googlegroups.com
Hi,

The error code AuthenticationError.OAUTH_TOKEN_INVALID indicates that there's an issue with the access token in the Authorization header. It usually means the token has expired, which you can confirm via the URL below after appending your access (not refresh) token to the end.


When you generated the refresh token did you use the GetRefreshToken.java example and follow the instructions on our wiki?

Thanks,
Josh, AdWords API Team

Van Sereyboth

unread,
Jan 7, 2015, 10:26:50 PM1/7/15
to adwor...@googlegroups.com
Hi I keep getting the above error while writing rspec in RoR.

The first attempt to request is always causing me this mentioned error.
the second attempt is working so fine without any glitches.

here is how I get after testing my access_token:

{

Josh Radcliff (AdWords API Team)

unread,
Jan 8, 2015, 10:18:45 AM1/8/15
to adwor...@googlegroups.com
Hi,

Could you provide some more details? For example, are you using one of the client libraries, or just constructing the OAuth and API requests manually? You mentioned that it works after your second attempt -- are you referring to your second attempt to get an access token using a refresh token, or something else?

If you have sample requests and responses (with any sensitive information removed), please post those as well to help us diagnose the problem.

Thanks,
Josh, AdWords API Team

Stephen Burrows

unread,
Feb 26, 2015, 2:28:48 PM2/26/15
to adwor...@googlegroups.com
My issue ended up being that I was using the authorization code as the access token. Ugh. For future reference, don't forget this step:

$OAuth2Handler = $user->GetOAuth2Handler();
$user->SetOAuth2Info($OAuth2Handler->GetAccessToken($user->GetOAuth2Info(), $_GET['code'], REDIRECT_URI));

Stephen Burrows

unread,
Feb 26, 2015, 2:29:11 PM2/26/15
to adwor...@googlegroups.com
Just tried again with a test account - got the same error.

Stephen Burrows

unread,
Feb 26, 2015, 2:29:11 PM2/26/15
to adwor...@googlegroups.com
I just ran into this error as well. I tried to go to the URL you provided, Josh, and got the following error:

{
 
"error": "invalid_token",
 
"error_description": "Invalid Value"
}

Which is weird since I just used that token to generate a refresh token.

Here's my code (essentially):
$oauth2Info = array(
    'client_id' => CLIENT_ID,
    'client_secret' => CLIENT_SECRET,
    'access_token' => $_GET['code'],
);
$user = new AdWordsUser(NULL, DEVELOPER_TOKEN, NULL, USER_AGENT, NULL, NULL, $oauth2Info);

$customerService = $user->GetService("CustomerService");
$customer = $customerService->get(); // this line errors
printf("You are logged in as customer: %s\n", $customer->customerId);

$user->LogAll();
$user->setCustomerId($customer->customerId);

$report = ReportUtils::DownloadReportWithAwql("
    SELECT *
    FROM KEYWORDS_PERFORMANCE_REPORT
    DURING LAST_7_DAYS
", CSV_PATH, $user, 'CSV');

I'm currently using my MCC account to test the OAuth2 flow, since that's the only account I have access to. Could that be the problem by any chance?

Stephen Burrows

unread,
Feb 26, 2015, 2:29:11 PM2/26/15
to adwor...@googlegroups.com
If I hardcode a customer client ID, I get the same error when I finally try to download the report.

Josh Radcliff (AdWords API Team)

unread,
Feb 26, 2015, 5:18:32 PM2/26/15
to adwor...@googlegroups.com
Hi,

To simplify things, have you tried setting the values in your auth.ini file, and then using the no-args AdWordsUser constructor? If that works, then we know that the issue is limited to the values you're passing to the constructor and we can proceed from there.

Thanks,
Josh, AdWords API Team

Stephen Burrows

unread,
Feb 26, 2015, 8:04:00 PM2/26/15
to adwor...@googlegroups.com
For some reason my responses got posted in reverse order... as mentioned above, the issue ended up being that I was using the auth code instead of first getting an actual access token.

Josh Radcliff (AdWords API Team)

unread,
Feb 27, 2015, 9:10:06 AM2/27/15
to adwor...@googlegroups.com
Hi Stephen,

Thanks for clarifying - this makes a lot more sense now. :)

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages