public ContactFeed retrieveContacts(ContactsService service,
Credential credential) throws Exception {
URL url = new URL("https://www.google.com/m8/feeds/profiles/domain/my.domain.com/full");
service.setOAuth2Credentials(credential);
service.useSsl();
service.setHeader("GData-Version", "3.0");
ContactFeed contactFeed = new ContactFeed();
do {
ContactFeed feedResult = service.getFeed(url, ContactFeed.class);
contactFeed.getEntries().addAll(feedResult.getEntries());
if (feedResult.getNextLink() != null && feedResult.getNextLink().getHref() != null
&& !feedResult.getNextLink().getHref().isEmpty()) {
url = new URL(feedResult.getNextLink().getHref());
} else {
url = null;
}
} while (url != null);
return contactFeed;
}
这是我用于检索配置文件的代码。当运行这条线时
ContactFeed feedResult = service.getFeed(query, ContactFeed.class);
它会给java.lang.NullPointerException:没有身份验证标头信息 error.
我的 Google 协作平台、Google 云端硬盘、Google Apps 配置、Google 电子邮件设置与 OAuth2 运行良好。但是带有 OAuth2 的 Google Apps 配置文件给出了java.lang.NullPointerException:没有身份验证标头信息。我上网查了一下,他们说这是一个错误?他们所做的只是手动将 AccessToken 传递到标头中。无论如何,有解决这个问题的方法吗?因为我使用它在 Cron Job 上运行并且我使用 OAuth2 服务帐户。
====
Edit:
我尝试使用设置标头来暴力破解它,如下所示:
service.setHeader("GData-Version", "3.0");
service.setUserCredentials(myusername, mypassword);
这工作得非常完美。 service.set OAuth2Credentials() 似乎内部存在错误。
我找到了为什么 service.setOAuth2Credentials() 不能用于构建新的 Google 凭据(使用 P12File 构建)的原因。
这是因为 service.set OAuth2Credentials() 没有刷新令牌内部就像 Google 协作平台、Google 云端硬盘等中的其他服务一样......
如果您使用 P12File 构建 Google Credential,只需在构建 Google Credential 后添加此行即可。
googleCredential.refreshToken();
我猜这是 ContactsService.setOAuth2Credentials() 的错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)