Problems with OAuth 2.0 (java)

268 views
Skip to first unread message

GrueneOrchidee

unread,
Oct 30, 2013, 10:26:19 AM10/30/13
to adwor...@googlegroups.com
I want to change the login from ClientLogin to OAuth2.0. I read so many tutorials about OAuth2.0 but it doesn't work.

I want a login mechanism without user interaction and without the use of a browser, so I decided to use Service Account. Therefore I created at Google Console an OAuth 2.0 Client ID by selecting 'service account'. The result was the file with the private key. Afterwards I tried to create a JWT and sign it with the private key. But I couldn't find a Java class at AdWords library (adwords-appengine) that can do this. Which class do I have to use?

Takeshi Hagikura (AdWords API Team)

unread,
Nov 6, 2013, 4:30:43 AM11/6/13
to adwor...@googlegroups.com
Hi,

You can use OAuth2 service account as in this guide
But if you don't use a service account specific feature (i.e. impersonation), I recommend using other authentication type, if you use app engine, web flow can be used. 

Even if you use other authentication types (installed application or web flow), user interaction is required only once. 

Best,
- Takeshi, AdWords API Team

GrueneOrchidee

unread,
Nov 21, 2013, 2:56:26 AM11/21/13
to adwor...@googlegroups.com

Hi Takeshi,

thanks for your answer. I already answered more than a week ago but this answer is not visible, so I try it again.

I tried using your guide but the method setAccessType("offline") is not available at class GoogleCredential of v201309 or v201306. Without this method call, I get the following exception:

<soap:Header>
<ResponseHeader xmlns="https://adwords.google.com/api/adwords/cm/v201306">
<requestId>0004ebab35eb23200ae56889000002cb</requestId>
<serviceName>AdGroupService</serviceName>
<methodName>get</methodName>
<operations>0</operations>
<responseTime>91</responseTime>
</ResponseHeader>
</soap:Header>
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>[AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'&lt;null&gt;']</faultstring>
<detail>
<ApiExceptionFault xmlns="https://adwords.google.com/api/adwords/cm/v201306">
<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>
</ApiExceptionFault>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

Takeshi Hagikura (AdWords API Team)

unread,
Nov 25, 2013, 11:10:04 PM11/25/13
to adwor...@googlegroups.com
Hi,

The documentation looks not right. 
There is no concept of access type for service accounts. 
We're fixing the sample code. For the time being please ignore the line of ".setAccessType("offline")".

The error messages seems you don't have a proper access token. 
When you invoked the .refreshToken() method, do you have an access token set to the GoogleCredential instance?

Best,
- Takeshi, AdWords API Team

GrueneOrchidee

unread,
Mar 14, 2014, 3:05:06 AM3/14/14
to adwor...@googlegroups.com
Hi,

thanks for your help. Now it works for me, but not with service accounts ;-)
Reply all
Reply to author
Forward
0 new messages