Hi Claudio,
I tried 2 Legged OAuth. But it doesn't work. Can you please help?
String CONSUMER_KEY = "
773845619631-hbtdlqoi1nm5pv76lkoj1ahk8gq6mbcm.apps.googleusercontent.com";
String CONSUMER_SECRET = "CX9-kaxMfzHzPQ4zu6uXZ3Dq";
GoogleOAuthParameters oauthParameters = new
GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
DocsService client = new DocsService("test");
client.setOAuthCredentials(oauthParameters, new
OAuthHmacSha1Signer());
// Retrieve user's list of Google Docs
String user = "[email protected]";
URL feedUrl = new URL("
https://docs.google.com/feeds/default/private/full" +
"?xoauth_requestor_id=" + user);
DocumentListFeed resultFeed = client.getFeed(feedUrl,
DocumentListFeed.class);
for (DocumentListEntry entry : resultFeed.getEntries()) {
System.out.println(entry.getTitle().getPlainText());
}
Exception:
com.google.gdata.util.AuthenticationException: Token invalid - Invalid
token: Invalid user for the two legged OAuth
<HTML>
<HEAD>
<TITLE>Token invalid - Invalid token: Invalid user for the two legged
OAuth</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid - Invalid token: Invalid user for the two legged
OAuth</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
Thanks,
On Fri, Mar 30, 2012 at 12:06 AM, Claudio Cherubino
<[email protected]>wrote:
> Hi,
>
> The GData Java library doesn't support OAuth 2.0 yet, but you can use
> OAuth 1.0.
> Please check the Java code at
>
> http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples
>
> Claudio
>
>
> On Thu, Mar 29, 2012 at 1:26 AM, sunz <[email protected]> wrote:
>
>> Hi..
>>
>> I am in a strange problem. I am writing an application in core java which
>> needs to access its own account at google docs. So after doing a lot of
>> googling, I found that OAuth2.0 with Service Account is something I am
>> looking for. But I am not using App Engine or anything. Its a simple
>> application. I don't know how can I use the OAuth. I have written below
>> code and I dont know how to proceed further. Looking for someone to guide
>> me further:
>>
>> GoogleCredential credential = new
>> GoogleCredential.Builder().setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY)
>>
>>
>>
>> .setServiceAccountId(EMAIL)
>>
>> .setServiceAccountScopes(SCOPE)
>>
>>
>>
>> .setServiceAccountPrivateKeyFromP12File(new File("lib/key.p12")).build();
>>
>>
>> SpreadsheetService service = new SpreadsheetService("My test Service");
>>
>> //service .setOAuthCredentials(parameters, signer);
>>
>> Please help.
>>
>>
>>
>