我正在使用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)
我的守则:
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();
}
}有什么特殊的方式来做身份验证,同时有两个步骤的认证。你能帮个忙吗。我被困在这里了。
发布于 2012-11-25 13:41:09
正如Google在2步文档中明确指出的那样,您不能使用常规密码进行API访问。
相反,您应该使用OAuth 2。
或者,您可以创建一个特定于应用程序的密码。
发布于 2012-12-06 06:03:56
试试这个!我希望它能帮上一点忙。当API请求失败时,HTTP将返回4xx或5xx响应代码,该响应代码一般标识故障,并返回一个XML响应,该响应提供了有关导致失败的错误的更具体信息。
https://stackoverflow.com/questions/13551525
复制相似问题