Hi,
This example uses Batch processing and OAuth:
ContactsService contactsService = new ContactsService("app-name");
// Oauth
OAuthSigner signer = new OAuthHmacSha1Signer();
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey("domain.com");
oauthParameters.setOAuthConsumerSecret("Etx...");
oauthParameters.setScope("http://www.google.com/m8/feeds/");
// Create ContactService and authenticate using oauth credentials
contactsService.setOAuthCredentials(oauthParameters, signer);
ContactEntry contactEntry1 = new ContactEntry();
contactEntry1.setTitle(new PlainTextConstruct("TestContactOauth1"));
BatchUtils.setBatchId(contactEntry1, "1");
BatchUtils.setBatchOperationType(contactEntry1,
BatchOperationType.INSERT);
ContactEntry contactEntry2 = new ContactEntry();
contactEntry2.setTitle(new PlainTextConstruct("TestContactOauth2"));
BatchUtils.setBatchId(contactEntry2, "2");
BatchUtils.setBatchOperationType(contactEntry2,
BatchOperationType.INSERT);
ContactFeed cf = new ContactFeed();
cf.getEntries().add(contactEntry1);
cf.getEntries().add(contactEntry2);
URL feedUrl2 = new URL("http://www.google.com/m8/feeds/contacts/
[email protected]/full/[email protected]");
ContactFeed resultFeed = contactsService.batch(feedUrl2, cf);
for(ContactEntry entry : resultFeed.getEntries()) {
if(BatchUtils.isSuccess(entry)) {
System.out.println("Operation " + BatchUtils.getBatchId(entry) + "
succeeded!");
String operation = BatchUtils.getBatchOperationType(entry).getName
();
System.out.println("The " + operation + " worked!");
}
else {
System.out.println("Operation " + BatchUtils.getBatchId(entry) +
"failed!");
BatchStatus status = BatchUtils.getBatchStatus(entry);
System.out.println(status.getCode() + " - " + status.getContent
());
}
}
--Julian
On Apr 27, 8:12 pm, Rhett <[email protected]> wrote:
> Can someone give me a simple example of how to add a ContactEntry
> using batch processing and OAuth. I have been able to do it using
> basic user/pass authentication but I need to be able to add contacts
> to all contact lists in a domain. I have added "?
> xoauth_requestor_id=<user>@<domain>" to the URL for the contact feed
> but I get this error; "java.lang.NullPointerException: No
> authentication header information" when I make the <ContactFeed>.insert
> (<ContactEntry>) call.
--~--~---------~--~----~------------~-------~--~----~
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]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-contacts-api?hl=en
-~----------~----~----~----~------~----~------~--~---