Hi

I think there is a problem in the order you set the OAuth Credentials,
please try the following:

ContactsService service = new ContactsService("contacts-tests-
script");

OAuthSigner signer = new OAuthHmacSha1Signer();
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(domain);
oauthParameters.setOAuthConsumerSecret(consumerSecret);
oauthParameters.setScope("http://www.google.com/m8/feeds/";);
service.setOAuthCredentials(oauthParameters, signer);
GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);

URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/default/
full/?xoauth_requestor_id=user%40domain.com");

  ContactEntry entry = new ContactEntry();
  Name name = new Name();
  FullName fullName = new FullName("TestContact","TestContact");
  name.setFullName(fullName);
  entry.setName(name);
  Email email = new Email();
  email.setAddress("testContact"+"@domain.com");
  email.setLabel("home");
  entry.addEmailAddress(email);
  service.insert(feedUrl,entry);

Cheers,
Julian

On Nov 7, 12:09 am, Brett <[email protected]> wrote:
> I've been able to successfully use the Java TwoLeggedOAuthExample:
>
> http://code.google.com/p/gdata-java-client/source/browse/trunk/java/s...
>
> 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

--

You received this message because you are subscribed to the Google Groups 
"Google Contacts API" group.
To post to this group, send email to [email protected].
For more options, visit this group at 
http://groups.google.com/group/google-contacts-api?hl=.


Reply via email to