1

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

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;
}

但我得到以下错误:

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)
4

2 回答 2

0

Try this feed url, always add the authenticated email id instead of default and access token.

feedUrl = new URL("https://www.google.com/m8/feeds/contacts/"+userEmail+"/full?access_token="+access);
于 2015-01-21T11:46:19.663 回答
0

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

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(consumerKey);
oauthParameters.setOAuthToken(accessToken);
contactsService.setOAuthCredentials(oauthParameters, signer);
于 2013-05-20T12:34:05.003 回答