When trying to use the contacts API using 2-legged OAuth I'm getting a NPE.
My code looks like:

        ContactsService client = new ContactsService("Kintris-kiim-source");
        String feed = 
"https://www.google.com/m8/feeds/contacts/default/full";;
        //String feed = "https://www.google.com/m8/feeds/contacts/"; + 
u.getLogin() + "/full";
        if (openIdUserInfo == null) {
            // OAUTH 2 3-legged
            client.setHeader("Authorization", "Bearer " + 
userSession.getOauthToken());
        } else {
            // OpenId 2-legged OAUTH
            GoogleOAuthParameters oauthParameters = new 
GoogleOAuthParameters();
            
oauthParameters.setOAuthConsumerKey(openIdUserInfo.getConsumerKey());
            
oauthParameters.setOAuthConsumerSecret(openIdUserInfo.getConsumerSecret());
            oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);
            
oauthParameters.setScope("https://www.google.com/m8/feeds/contacts/default/full";);
            OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();

            try {
                client.setOAuthCredentials(oauthParameters, signer);
            } catch (OAuthException e) {
                throw new InvalidParameterException(e.getMessage());
            }
            feed += ("?xoauth_requestor_id=" + u.getLogin());
       }
        java.net.URL feedUrl = null;
        try {
            feedUrl = new java.net.URL(feed);
        } catch (MalformedURLException ex) {
            throw new UnauthorizedException(ex.getMessage());
        }
        ContactEntryBeanList resultBean = new ContactEntryBeanList();
        int startIndex = 1;
        boolean gotAtLeastOne = true;
        while (gotAtLeastOne) {
            gotAtLeastOne = false;
            ContactFeed resultFeed = null;
            Query myQuery = new Query(feedUrl);
            myQuery.setStartIndex(startIndex);
            myQuery.setMaxResults(2500);
            try {
                resultFeed = client.query(myQuery, ContactFeed.class);

I've verified that all APIs for domain users are enabled and that I'm using 
the correct consumer key and secret.
(The same key and secret work when using them with 2-legged oauth with 
documents list API.)

        DocsService client = new DocsService("Kintris-kiim-source");
        String feed = "https://docs.google.com/feeds/default/private/full";;
        if (openIdUserInfo == null) {
            // OAUTH 2 3-legged
            client.setHeader("Authorization", "Bearer " + 
userSession.getOauthToken());
        } else {
            // OpenId 2-legged OAUTH
            GoogleOAuthParameters oauthParameters = new 
GoogleOAuthParameters();
            
oauthParameters.setOAuthConsumerKey(openIdUserInfo.getConsumerKey());
            
oauthParameters.setOAuthConsumerSecret(openIdUserInfo.getConsumerSecret());
            oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);
            OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();

            try {
                client.setOAuthCredentials(oauthParameters, signer);
            } catch (OAuthException e) {
                throw new InvalidParameterException(e.getMessage());
            }
            feed += ("?xoauth_requestor_id=" + u.getLogin());
       }
        java.net.URL feedUrl = null;
        try {
            feedUrl = new java.net.URL(feed);
        } catch (MalformedURLException ex) {
            throw new UnauthorizedException(ex.getMessage());
        }
        DocumentListFeed resultFeed = null;
        try {
            resultFeed = client.getFeed(feedUrl, DocumentListFeed.class);
        } catch (IOException ex) {
            throw new UnauthorizedException(ex.getMessage());
        } catch (ServiceException ex) {
            throw new UnauthorizedException(ex.getMessage());
        }


The problem only shows up using the Contacts API.

Any suggestions?

Thanks,

Tom


-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html

Reply via email to