I've been able to successfully use the Java TwoLeggedOAuthExample:
http://code.google.com/p/gdata-java-client/source/browse/trunk/java/sample/oauth/TwoLeggedOAuthExample.java
In the process of ripping out the code I don't need for my purposes,
I've taken out the interactivity and used ContactsService instead of
the generic GoogleService. I can pull the Contacts feed just fine,
but I cannot create new contacts:
// works fine
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters
();
oauthParameters.setOAuthConsumerKey(consumerKey);
oauthParameters.setOAuthConsumerSecret(consumerSecret);
oauthParameters.setScope("
http://www.google.com/m8/feeds/
contacts/");
// Finally create a new GoogleOAuthHelperObject. This is the
object you
// will use for all OAuth-related interaction.
OAuthSigner signer = new OAuthHmacSha1Signer();
GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
ContactsService cService = new ContactsService("Bulk-Contacts");
cService.setOAuthCredentials(oauthParameters, signer);
URL feedUrl = new URL("
http://www.google.com/m8/feeds/contacts/
default/base?xoauth_requestor_id=" + email);
System.out.println("Sending request to " + feedUrl.toString());
// Make the request to Google
ContactFeed resultFeed = cService.getFeed(feedUrl,
ContactFeed.class);
System.out.println
("=====================================================");
System.out.println("TITLE: " + resultFeed.getTitle().getPlainText
());
// Does not work (same cService used, already successfully
authenticated and feed pulled)
URL postUrl = new URL("
http://www.google.com/m8/feeds/contacts/" +
email + "/full");
ContactEntry ce = getContact();
System.out.print(cService.insert(postUrl, ce));
I get: "Caused by:
com.google.gdata.client.authn.oauth.OAuthException: oauth_token does
not exist."
Do I need additional steps to POST to create a contact that I don't
need when just pulling a feed?
Thanks,
-b