0

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

0 Answers0