首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Contact API错误

Google Contact API错误
EN

Stack Overflow用户
提问于 2012-11-25 13:37:49
回答 2查看 3.3K关注 0票数 0

我正在使用Google通过java访问我的联系人。我正在用我的gmail帐户来做这个。我的帐户有双向密码认证。所以我写了一个示例程序来显示标题。但我的错误就像

线程“主”com.google.gdata.client.GoogleService$InvalidCredentialsException:中的异常无效凭据在com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(GoogleAuthTokenFactory.java:600) at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactory.java:500) at com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(GoogleAuthTokenFactory.java:346) at com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:362) at com.google.gdata.client.GoogleServicecom.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:301) at com.contact.manager.Create.createContact(Create.java:15) at com.contact.manager.Create.main(Create.java:26) .setUserCredentials(GoogleService.java:317)

我的守则:

代码语言:javascript
复制
public class Create {

    public void createContact() throws IOException, ServiceException {
        ContactsService contactsService = new ContactsService(
                "mine-MyProduct-3");
        contactsService.setUserCredentials(username,
                password);
        URL feedUrl = new URL(
                "https://www.google.com/m8/feeds/contacts/{EmailID}/full");
        ContactFeed resultedFeed = contactsService.getFeed(feedUrl,
                ContactFeed.class);
        System.out.println(resultedFeed.getTitle().getPlainText());
    }

    public static void main(String[] args) throws IOException, ServiceException {
        Create create = new Create();
        create.createContact();
    }
}
  1. 我正在使用两个步骤的身份验证我的帐户,当时我正在收到这样的错误。
  2. 在使用普通帐户时(我指的是一步认证),我没有收到任何错误。

有什么特殊的方式来做身份验证,同时有两个步骤的认证。你能帮个忙吗。我被困在这里了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-25 13:41:09

正如Google在2步文档中明确指出的那样,您不能使用常规密码进行API访问。

相反,您应该使用OAuth 2。

或者,您可以创建一个特定于应用程序的密码。

票数 1
EN

Stack Overflow用户

发布于 2012-12-06 06:03:56

试试这个!我希望它能帮上一点忙。当API请求失败时,HTTP将返回4xx或5xx响应代码,该响应代码一般标识故障,并返回一个XML响应,该响应提供了有关导致失败的错误的更具体信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13551525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档