SilverHoodCorp / gdata-java-client

Automatically exported from code.google.com/p/gdata-java-client
Apache License 2.0
0 stars 0 forks source link

Gdata Java Contact API : "No authentication header information" when adding a parameter to a Query using 2-legged OAuth #257

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Here is my simple code:

// Setup Oauth
GoogleOAuthParameters oauthParam = new GoogleOAuthParameters();
oauthParam.setOAuthConsumerKey(oAuthConsumerKey);
oauthParam.setOAuthConsumerSecret(oAuthConsumerSecret);
oauthParam.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);

// set the feedURL (googleAccount = you@yourdomain.com)
contactsFeedUrl = new URL(METAFEED_URL_CONTACTS + "?xoauth_requestor_id=" +
this.googleAccount);

// Init the service and set the auth
contactsService = new ContactsService("myerp.com");
contactsService.setOAuthCredentials(oauthParam, new OAuthHmacSha1Signer());

// The query that will retrieve all contacts
Query myQuery = new Query(contactsFeedUrl);

// Execute the request
ContactFeed resultFeed = contactsService.getFeed(myQuery, ContactFeed.class);

-----------------

The code above works. But if I add before executing the request

myQuery.setMaxResults(MAX_RESULT);

it fails with 

java.lang.NullPointerException: No authentication header information 
at
com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationE
xception.java:96)
at
com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.jav
a:67)
at
com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataReque
st.java:596)
at
com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataR
equest.java:563)

I'm using gdata 1.41.1, java 6

Original issue reported on code.google.com by thomas.r...@gmail.com on 11 Apr 2010 at 2:46

GoogleCodeExporter commented 9 years ago

Original comment by yanivin...@gmail.com on 28 Apr 2010 at 3:27

GoogleCodeExporter commented 9 years ago
Hi,

I tried the same, but could not able to get contact list in my account.:

The code snippet is below: 

<code>
    //Setup Oauth
    GoogleOAuthParameters oauthParam = new GoogleOAuthParameters();
    oauthParam.setOAuthConsumerKey("810057834155.apps.googleusercontent.com");
    oauthParam.setOAuthConsumerSecret("duJ77pNlETvfEDUIns1TXGZ4");
    oauthParam.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);

    // set the feedURL (googleAccount = you@yourdomain.com)
    URL contactsFeedUrl = null;
    try {
        contactsFeedUrl = new URL("http://www.google.com/m8/feeds/contacts/default/full" + "?xoauth_requestor_id=" + "vikash.kumar@gmail.com");
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // Init the service and set the auth
    ContactsService contactsService = new ContactsService("atos-guestbook");
    try {
        contactsService.setOAuthCredentials(oauthParam, new OAuthHmacSha1Signer());
    } catch (OAuthException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // The query that will retrieve all contacts
    //Query myQuery = new Query(contactsFeedUrl);
    //System.out.println("max results :: " + myQuery.getMaxResults());
    // Execute the request
    try {
    //  ContactFeed resultFeed = contactsService.getFeed(myQuery, ContactFeed.class);
        ContactFeed resultFeed = contactsService.getFeed(contactsFeedUrl, ContactFeed.class);
        System.out.println("resultFeed.getEntries().size() " + resultFeed.getEntries().size());

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    }
</code>

Please suggest. 

My requirement is to fetch all the contact list of the gmail user who is 
accessing an application deployed on Google Appengine.

Thanks.

Original comment by vikash.c...@gmail.com on 31 Aug 2012 at 6:57