Found the problem here:
http://www.google.com/support/forum/p/apps-apis/thread?tid=1a1d15094874989e&hl=en myQuery.addCustomParameter(new CustomParameter("xoauth_requestor_id", u.getLogin())); instead of adding ?xoauth_requestor_id=name on url. On Friday, March 23, 2012 11:16:25 AM UTC-7, Tom Saulpaugh wrote: > > 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<https://www.google.com/m8/feeds/contacts/default/full> > "; > //String feed = > "https://www.google.com/m8/feeds/contacts/<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<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<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
