Score:0

com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized when I try to create a google people contact

tj flag

Good day.

I'm developing a java servlet that allow to add or update a contact on Google Contact. I've created a Google application having Google People service active. Before to use the Google People service I made a Google connection (https://accounts.google.com/o/oauth2/auth) including between other parameters the scope (openid%20email) and the clientid created in the Google application. Get the access token (https://accounts.google.com/o/oauth2/token) and the user id (https://www.googleapis.com/oauth2/v1/userinfo), I use the class GoogleAuthorizationCodeFlow.Builder passing ClientId, ClientSecret (both read from Google application) and PeopleServiceScopes.CONTACTS as scope. Then I tryied to instance the Credential class using loadCredential method of GoogleAuthorizationCodeFlow obtained before (passing the user id), but is null. So I use createAndStoreCredential method of GoogleAuthorizationCodeFlow passing as parameters the access token and the user idn and I obtained the Credential class. At this point I've instantiated PeopleService class and the class Person where I put the values obtained from user input. When I make service.people().createContact(person).execute().getResourceName() in order to create a new contact and obtains the resource name, this error appears: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized POST https://people.googleapis.com/v1/people:createContact

Why?

Best regards.

Stefano Errani

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.