#前言
我用Gmail觉得地址簿操作不方便。幸好Google提供了API方便自己整理地址簿了。
参考 : http://code.google.com/intl/ja/apis/contacts/docs/3.0/developers_guide_java.html
#认证
public ContactsUtils() throws ServiceException, IOException {
service = new ContactsService("Google-contactsExampleApp-3");
String userName = "your mail address";
String password = "your password";
service.setUserCredentials(userName, password);
}
#加一个联系人
public ContactEntry createContact(String fullName, String mailAddr)
throws ServiceException, IOException {
ContactEntry contact = new ContactEntry();
Name name = new Name();
final String NO_YOMI = null;
name.setFullName(new FullName(fullName, NO_YOMI));
contact.setName(name);
Email primaryMail = new Email();
primaryMail.setAddress(mailAddr);
primaryMail.setRel("http://schemas.google.com/g/2005#home");
primaryMail.setPrimary(true);
contact.addEmailAddress(primaryMail);
URL postUrl = new URL(CONTACT_URL);
return service.insert(postUrl, contact);
}
#加一个组
public ContactGroupEntry addGroup(String name) throws ServiceException, IOException {
ContactGroupEntry group = new ContactGroupEntry();
group.setTitle(new PlainTextConstruct(name));
URL postUrl = new URL(GROUP_URL);
return service.insert(postUrl, group);
}
附件是完整的例子