contactlist

contactlist是一个获取用户的msn和邮箱联系人列表的java类库,支持的邮箱包括hotmail, gmail, yahoo, sohu, sina, 163, 126, tom, yeah, 189和139。

contactlist项目首页和jar包下载在 http://code.google.com/p/contact-list/

contactlist项目源代码在 http://github.com/flyerhzm/contactlist , google code svn不再更新


Service

contactlist提供web api调用,接口如下:

url: https://123.183.209.87:8443/ContactListService/contacts
parameters: account=xxx@gmail.com&password=xxxx&type=gmail

返回json格式如下:
正确的结果:

{'contacts': [{'username': 'yyy', 'email': 'yyy@gmail.com'}, {'username': 'zzz', 'email': 'zzz@hotmail.com'}]}

错误的结果:
{'error': 'hotmail protocol changed'}

ruby客户端: contactlist-client

web客户端: http://contactlist.heroku.com


Example


try {
    ContactsImporter importer = ContactsImporterFactory.getHotmailContacts(username, password);
    List<Contact> contacts = importer.getContacts();
    for (Contact contact : contacts) {
        System.out.println(contact.getUsername() + ": " + contact.getEmail());
    }
} catch (ContactsException ex) {
    ex.printStackTrace();
}

Encoding

项目的输出统一为UTF-8。
对于运行在locale为UTF-8环境(如:Ubuntu, Mac OS X)下的程序,无需任何调整。
对于运行在locale为GBK环境(如:Windows XP)下的程序,需要手动调整编码:


try {
    ContactsImporter importer = ContactsImporterFactory.getHotmailContacts(username, password);
    List<Contact> contacts = importer.getContacts();
    for (Contact contact : contacts) {
        String username = new String(contact.getUsername().getBytes("UTF-8"), "GBK");
        System.out.println(username + ": " + contact.getEmail());
    }
} catch (ContactsException ex) {
    ex.printStackTrace();
}

另外,在windows下面需要把项目的编码设置为UTF-8,并且确保java文件的编译是用UTF-8的


Project Introduction

contact-list类库依赖包之commons-httpclient — http://www.huangzhimin.com/entries/142-contact-list-library-dependency-of-commons-httpclient
contact-list类库依赖包之msnmlib — http://www.huangzhimin.com/entries/147-contact-list-library-dependency-of-msnmlib
contact-list类库依赖包之json — http://www.huangzhimin.com/entries/158-contact-list-of-the-json-library-dependency
contact-list类库依赖包之gdata — http://www.huangzhimin.com/entries/162-contact-list-of-the-gdata-library-dependency

持续更新中…


How to run unit test

出于安全的考虑,没有把单元测试中的邮箱配置文件和msn配置文件放到svn上,如果需要运行mvn test的话,可以按以下步骤:

  • 新建src/test/resources/email.properties文件,形式如下:

gmail.username = xxx@gmail.com
gmail.password = yyy

hotmail.username = xxx@hotmail.com
hotmail.password = yyy

livecn.username = xxx@live.cn
livecn.password = yyy

onesixthree.username = xxx@163.com
onesixthree.password = yyy

onetwosix.username = xxx@126.com
onetwosix.password = yyy

sina.username = xxx@sina.com
sina.password = yyy

sohu.username = xxx@sohu.com
sohu.password = yyy

tom.username = xxx@tom.com
tom.password = yyy

yahoo.username = xxx@yahoo.com
yahoo.password = yyy

yahoocn.username = xxx@yahoo.cn
yahoocn.password = yyy

yahoocomcn.username = xxx@yahoo.com.cn
yahoocomcn.password = yyy

yeah.username = xxx@yeah.net
yeah.password = yyy

oneeightnine.username = xxx@189.cn
oneeightnine.password = yyy

onethreenine.username = xxx@139.com
onethreenine.password = yyy
  • 新建src/test/resources/msn.properties文件,形式如下:

username = xxx@live.cn
password = yyy
  • 在命令行执行mvn test

Change Log

  • 1.1:
    First public release
  • 1.2:
    Fix issue that hotmail can only get first page contact list
  • 1.3:
    Fix issue for some special sohu mail account
  • 1.4:
    Fix issue that 163 mail can only get other group contacts
  • 1.5:
    Fix issue that 126 and yeah mail can only get other group contacts
  • 1.6:
    Add 189 and 139 mail support
  • 1.6.1:
    Meet another style 189 mail and add 139 mail importer to ContactsImporterFactory
  • 1.7.0:
    Get google contacts by gdata api
  • 1.8.0:
    Get hotmail contacts by windows live contacts api
  • 1.9.0:
    Better parser for yahoo and tom mail
  • 1.10.0:
    Use passportName as email for hotmail
  • 1.11.0:
    Fix 139 for web change and fix 126 and yeah mail when username is empty
  • 1.12.0:
    Get msn contacts by window live contacts api

Other

需要留言的话,可以上 http://github.com/flyerhzm/contactlist/issues ,我会尽快回复的

由于这个类库的原理是使用抓取网页来分析联系人列表的,所以会因为邮箱网页的改版而无法正确获取联系人列表。
如果大家在使用的时候发现有邮箱不能获得联系人列表,希望先把类库log4j的level设置为debug,把调试信息和错误信息一起发送给我flyerhzm@gmail.com,我会尽快解决问题的,谢谢!

  1. zhangcaiyan at 2010-01-28 10:25:49 +0800 Said,

    您好,我应该怎么部署这个项目到服务器上,也不知道该怎么测试。。。。

  2. Ccc at 2010-01-30 01:39:37 +0800 Said,

    你好,请问一下,是否可以考虑给组件加一个判断,如果是用户名密码不匹配的,返回个标志信息。

  3. huang zhimin at 2010-04-04 23:45:54 +0800 Said,

    to @zhangcaiyan, 这个只是一个类库,只要通过服务器上的代码调用提供的接口就可以了。

  4. huang zhimin at 2010-04-04 23:46:18 +0800 Said,

    to @Ccc, 这个可能需要一些时间,可以考虑。

  5. 63345133@qq.com at 2010-04-07 16:45:33 +0800 Said,

    你好,我用rails的客户端,照你的例子写,报错:in `gem_original_require': no such file to load -- json (LoadError) 这是什么原因呢? ruby版本是1.8.6 rails:2.3.6

  6. huang zhimin at 2010-04-07 20:06:00 +0800 Said,

    执行sudo gem install json就可以了

  7. guoyang at 2010-04-16 16:33:13 +0800 Said,

    导不了hotmail了

  8. guoyang at 2010-04-16 16:43:49 +0800 Said,

    您好,我用了您的contactlist.jar ,可是其他邮箱都没问题,但是导hotmail的时候却出Hotmail protocol has changed,是不是因为hotmail的protocol改了就不能导出了?

  9. yangyang at 2010-04-16 16:48:14 +0800 Said,

    您好,我看了一下contactlist的源码,是抓取网页的,那就是说,一旦人家的protocol改变,我们就不能用了是吗,就像这个hotmail,以前能用的吧,它改的频繁,那hotmail就导不了啦?

  10. Huang Zhimin at 2010-04-16 21:16:25 +0800 Said,

    我测试了一个hotmail没有问题,你们是不是用的是旧版本的呀?最新的1.12.0

  11. yangyang at 2010-04-17 19:31:50 +0800 Said,

    不会啊,我下的是最新版本,而且其他邮箱都好用啊,只有hotmail不行,那您知不知道我可能会有其他什么地方犯错了呢?有没有什么提示啊!

  12. Huang Zhimin at 2010-04-17 22:17:47 +0800 Said,

    @yangyang,我试了下自己的两个hotmail账号,都可以获取到联系人。你首先确认自己的账号和密码是正确的,如果还是不能导入联系人,你就私下给我你的账号和密码,我可以帮你调试看看

  13. yangyang at 2010-04-19 10:59:44 +0800 Said,

    我又来了,很麻烦您,不过,不知道这个程序怎么会挑账号呢,我自己的yahoo账号就能导,朋友的yahoo账号就导不了,可能您的hotmail可以导,我的也导不了,这可能是怎么回事呢,要崩溃了!呜呜···

  14. kama at 2010-06-23 17:21:43 +0800 Said,

    你好,为什么我使用刚注册的邮箱新加联系人都返回空的呀

  15. kama at 2010-06-23 17:27:36 +0800 Said,

    log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.HttpClient). log4j:WARN Please initialize the log4j system properly.

  16. Huang Zhimin at 2010-06-23 20:37:16 +0800 Said,

    @kama 163邮箱好像有点问题,周末有时间我会修复的

  17. louise at 2010-06-25 15:39:01 +0800 Said,

    您好,好几种邮箱的protocol has changed。希望可以在接下来的版本中修复这些bug。

  18. amanda at 2010-06-28 15:21:51 +0800 Said,

    你好,刚才调试了下发现有些邮箱无法导出了,具体信息已经发到了flyerhzm@gmail.com邮箱中,感谢分享

  19. chinadhtml at 2010-07-06 10:26:26 +0800 Said,

    189信箱不能用

  20. 谢金龙 at 2010-07-12 09:41:04 +0800 Said,

    163 126 不能用

  21. Huang Zhimin at 2010-07-12 14:17:33 +0800 Said,

    @谢金龙 试试看1.13.0版本

  22. ZZ at 2010-08-22 23:47:56 +0800 Said,

    1.13没问题,但是1.16就有了,1631.13是可以的

  23. ZZ at 2010-08-22 23:50:02 +0800 Said,

    而且1.16的jar包少了好多

  24. Huang Zhimin at 2010-08-23 12:12:32 +0800 Said,

    @ZZ, 你是不是下载错了,每个版本都有两个包可以下载,一个是不包含依赖包的,一个是包含依赖包的

  25. cc at 2010-08-27 12:00:06 +0800 Said,

    msn联系人取不到,返回的是空

Add a Comment

22d8c9577b69dfed3b600b2414a073552914c519