Google profiles api Google Apps Profiles API:java.lang.NullPointerException:无身份验证标头信息
这是我检索配置文件的代码。运行这条线路时Google profiles api Google Apps Profiles API:java.lang.NullPointerException:无身份验证标头信息,google-profiles-api,Google Profiles Api,这是我检索配置文件的代码。运行这条线路时 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
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;
}
它将给出java.lang.NullPointerException:无身份验证头信息错误。我有谷歌网站,谷歌驱动器,谷歌应用程序设置,谷歌电子邮件设置运行良好的OAuth2。但是使用OAuth2的Google应用程序配置文件提供了java.lang.NullPointerException:没有身份验证头信息。我在网上冲浪,他们说这是虫子?他们所做的只是手动将AccessToken传递到头中。这项工作有什么好处吗?因为我使用它来运行Cron作业,并且使用OAuth2服务帐户 ==== 编辑: 我试着用如下的设置标题来强制它:
ContactFeed feedResult = service.getFeed(query, ContactFeed.class);
这真是太好了。service.setOAuth2Credentials()内部似乎有bug。我找到了service.setOAuth2Credentials()无法构建新的Google凭证(使用p12文件构建)的原因 这是因为service.setOAuth2Credentials()不像谷歌网站、谷歌硬盘等中的其他服务那样,在内部刷新令牌 如果您使用P12文件构建Google凭证,只需在构建Google凭证后添加这一行即可
service.setHeader("GData-Version", "3.0");
service.setUserCredentials(myusername, mypassword);
我想这是ContactsService.setOAuth2Credentials()的一个bug。我在使用SecureSociale进行身份验证时遇到了这个问题 在我的例子中,问题与SecureSociale配置中定义的范围有关
不要忘记检查您的令牌是否使用了正确的作用域。您是否解决了该问题。如果是,请分享解决方案。谢谢
googleCredential.refreshToken();