【问题标题】:Fetching contacts from gmail -closed从 gmail 获取联系人 - 已关闭
【发布时间】:2013-10-28 09:31:34
【问题描述】:

我正在尝试使用

获取 gmail 的联系人

Google 通讯录 API

Oauth 2.0 API。

我对这个概念完全陌生。我正在尝试this 链接中给出的相同代码来获取所有联系人,但不知何故它不起作用。

我的代码

ContactsService service = new ContactsService("<var>Contacts
Fetcher</var>"); // Exception on this line 
    public ContactsService authenticateId() 
    { 
        try 
        { 
            service.setUserCredentials("example@gmail.com", "123456"); 
        } 
        catch(Exception e) 
        { 
            e.printStackTrace(); 
        } 
        return service; 
    } 

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
    at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
    at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
    at com.google.gdata.client.Service.<clinit>(Service.java:558)
    at javamails.ContactsFetcher.<init>(ContactsFetcher.java:25)
    at javamails.ContactsFetcher.main(ContactsFetcher.java:68)

我尝试阅读 google 提供的参考资料和文档,但似乎对我没有多大帮助。如果有人有一个简单的例子或其他 api 来获取 gmail 联系人,请告诉我。

【问题讨论】:

    标签: java gmail google-contacts-api


    【解决方案1】:

    确保包含您在运行时使用的库所需的依赖项。您似乎忘记包含 Guava 库。因此无法找到com.google.common.collect.ImmutableSet.copyOf 方法(在该库中定义)。

    如果您告诉我们有关如何编译和运行代码的更多信息,我们可以告诉您要更改的设置。

    【讨论】:

    • 什么都没有发生同样的异常再次发生:(
    • a) 你能从 Guava 库中调用其他方法吗? b) 在 Guava 3.0 中添加了copyOf 方法。也许您使用的是过时版本的番石榴?
    • 我为我的项目导入的所有 jar 文件都发生了冲突。感谢您的回答
    猜你喜欢
    • 2010-11-03
    • 1970-01-01
    • 2014-06-21
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    相关资源
    最近更新 更多