java.lang.NullPointerException: нет информации заголовка аутентификации google oauthentication - PullRequest
1 голос
/ 18 ноября 2011

Я использую клиентские библиотеки Google Data Protocol для аутентификации моих пользователей.Вот код, который у меня есть:

        GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();

        oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);

        oauthParameters.setOAuthConsumerSecret(SECRET_KEy);
        GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(new OAuthHmacSha1Signer());
        oauthParameters.setScope(SCOPE);
        oauthParameters.setOAuthVerifier(oauth_verifier);
        oauthParameters.setOAuthToken(oauth_token);
        oauthParameters.setOAuthTokenSecret(oauth_token_secret)
        String token = oauthHelper.getAccessToken(oauthParameters);
        System.out.println("here");
        ContactsService  client=new ContactsService ("myapp");
        client.setOAuthCredentials(oauthParameters, new hHmacSha1Signer());
        URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
        ContactFeed resultFeed = client.getFeed(feedUrl, ContactFeed.class);
        for (int i = 0; i < resultFeed.getEntries().size(); i++) {
            ContactEntry entry = (ContactEntry) resultFeed.getEntries().get(i);
            System.out.println("|\t" + (i + 1) + ": "
                    + entry.getTitle().getPlainText());
        }

, но в этой строке

ContactFeed resultFeed = client.getFeed(feedUrl, ContactFeed.class);

я получаю следующее исключение:

    java.lang.NullPointerException: No authentication header information
        com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)
        com.google.gdata.util.AuthenticationException.<init>(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:1077)
        com.google.gdata.client.GoogleService.getFeed(GoogleService.java:662)
        com.google.gdata.client.Service.query(Service.java:1237)
        com.google.gdata.client.Service.query(Service.java:1178)
        com.raisonne.oauth.CallBackAction.execute(CallBackAction.java:66)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    ....

Я уже подал заявкучто было упомянуто на различных форумах, но это не решило проблему.Что я должен сделать, чтобы это исправить?

Ответы [ 2 ]

0 голосов
/ 16 июля 2012

У меня была такая же проблема, но после многих изменений мой код работал. Попробуйте добавить эти две строки:

oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);
client.setHeader("Authorization", "Bearer " + oauth_token);
0 голосов
/ 19 февраля 2012

Установите область действия:

oauthParameters.setScope("http://www.google.com/m8/feeds/contacts/default/full");
...