Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Google Contacts API Java时未获得身份验证标头信息错误_Java_Contacts - Fatal编程技术网

使用Google Contacts API Java时未获得身份验证标头信息错误

使用Google Contacts API Java时未获得身份验证标头信息错误,java,contacts,Java,Contacts,我收到AuthSub令牌,并使用它从google检索所有联系人。代码片段 try { URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/base?max-results=" + maxresult); ContactsService service = new ContactsService("Google-contactsExampleApp-1"); service.setA

我收到AuthSub令牌,并使用它从google检索所有联系人。代码片段

try {
    URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/base?max-results=" + maxresult);
    ContactsService service = new ContactsService("Google-contactsExampleApp-1");
    service.setAuthSubToken(sessionToken, getPrivateKey());

    ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
    ArrayList<UserContact> ucList = new ArrayList<UserContact>(resultFeed.getEntries().size());
    for (ContactEntry entry : resultFeed.getEntries()) {
        if (entry == null || entry.hasDeleted()) {
            continue;
        }
        ucList.add(parseEntry(entry));
    }
    return ucList;
} catch (Exception e) {
    LOGGER.log(Level.WARNING, null, e);
    return null;
}
试试看{
URL feedUrl=新URL(“https://www.google.com/m8/feeds/contacts/default/base?max-results=“+maxresult);
ContactsService服务=新的ContactsService(“Google-ContactsExamplePP-1”);
setAuthSubToken(sessionToken,getPrivateKey());
ContactFeed resultFeed=service.getFeed(feedUrl,ContactFeed.class);
ArrayList ucList=新的ArrayList(resultFeed.getEntries().size());
for(ContactEntry:resultFeed.getEntries()){
if(entry==null | | entry.hasdelected()){
继续;
}
ucList.add(parseEntry(entry));
}
返回ucList;
}捕获(例外e){
LOGGER.log(Level.WARNING,null,e);
返回null;
}
但我的错误如下:

java.lang.NullPointerException: No authentication header information
at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)
at com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.java:67)
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:998)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
java.lang.NullPointerException:无身份验证头信息
位于com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)
位于com.google.gdata.util.AuthenticationException。(AuthenticationException.java:67)
位于com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
位于com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
位于com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
位于com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
位于com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
位于com.google.gdata.client.Service.getFeed(Service.java:1135)
位于com.google.gdata.client.Service.getFeed(Service.java:998)
位于com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
位于com.google.gdata.client.Service.getFeed(Service.java:1017)

我相信您需要调用setOAuthCredentials才能获得访问权限。以下是相同的示例:

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(consumerKey);
oauthParameters.setOAuthToken(accessToken);
contactsService.setOAuthCredentials(oauthParameters, signer);

尝试此源url,始终添加经过身份验证的电子邮件id,而不是默认的和访问令牌

feedUrl = new URL("https://www.google.com/m8/feeds/contacts/"+userEmail+"/full?access_token="+access);

还没有移动到oauth。这就是问题所在。对于身份验证,请注意要设置的任何凭据。谢谢你的回答