我使用谷歌API联系为通过Java访问我的联系人。我正在使用我的Gmail帐户。我的帐户有双向密码验证。所以我写了一个示例程序来显示标题。在 com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(GoogleAuthTokenFactory 证书无效:但我收到错误,如螺纹谷歌联系API错误
异常 “主要” com.google.gdata.client.GoogleService $ InvalidCredentialsException。的java:600) 在 com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(GoogleAuthTokenFactory.java:500) 在 com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(GoogleAuthTokenFactory.java:346) 在 COM .google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:362) 在 com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:317) 在 com.google.gdata.client.GoogleService.setUserCredentials(GoogleService.java:301) 在com.contact.manager。 Create.createContact(Create.java:15)在 com.contact.manager.Create.main(Create.java:26)
我的代码:
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();
}
}
- 我使用两在那T我的帐户进行一步验证ime我得到这样的错误。
- 在使用普通帐户(我的意思是一个一步到位的认证),我没有收到任何类型的错误。
有什么特殊的方式,同时具有两步认证做认证。 你能帮忙解决这个问题吗?我困在这里。
嗨,感谢您的回复。我不明白什么是应用程序特定的密码。我如何创建该密码。您能否提供如何使用OAuth2身份验证进行身份验证?如果您提供任何示例代码,对我更有帮助。 – Amar
http://support.google.com/accounts/bin/answer.py?hl=en&answer=185833 – SLaks
https://developers.google.com/accounts/docs/OAuth2 – SLaks