Good day.
I've created a Tomcat's web application that manage Google Contact through my Google app.
I haven't problem creating or deleting contact, but when i try to update it an exception occur.
Using service.people().updateContact("people/c3001613119211561864", person).execute(); when service is a PeopleService class and person is a com.google.api.services.people.v1.model.Person class that I set in several its fields this is the result:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
POST https://people.googleapis.com/v1/people/c3001613119211561864:updateContact
{
"code": 400,
"errors": [
{
"domain": "global",
"message": "updatePersonFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/updateContact.",
"reason": "badRequest"
}
],
"message": "updatePersonFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/updateContact.",
"status": "INVALID_ARGUMENT"
}
If I try to use
service.people().updateContact("people/c3001613119211561864", person).setPersonFields("person.names,person.emailAddresses,person.addresses,person.phoneNumbers,person.urls,person.occupations,person.userDefined,person.etag").execute();
this is the error that appear
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
POST https://people.googleapis.com/v1/people/c3001613119211561864:updateContact?personFields=person.names...
{
"code": 400,
"errors": [
{
"domain": "global",
"message": "updatePersonFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/updateContact.",
"reason": "badRequest"
}
],
"message": "updatePersonFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/updateContact.",
"status": "INVALID_ARGUMENT"
}
How can I resolve the problem?
Best regards.
Stefano Errani
I'm not sure about this API, but in the python code that I write to call Google APIs that need fields specified, here's what a call typically looks like:
service.files().list(pageSize=100, q="'user@example.com' in owners", fields="nextPageToken,incompleteSearch,files(mimeType,parents,shared,size,permissions(type,emailAddress,role,deleted),id,name)", orderBy="createdTime").execute()
Does that help, perhaps?
Cheers,
Ian
Thanks for reply.
Actually what generates error is the function of updating an existing contact created by the method
String idgc = service.people().createContact(person).execute().getResourceName();
where idgc is the id of Google Contact created (people/c3001613119211561864).
The service class of both methods are generated in the same servlet with the same code and createContact run correctly.
Also the person class is the same and populated with the same values.
I think I make some mistake in the call of the updateContact method or that something is missing before or during the same.
But I don't know what.
Best regards.
Stefano Errani
As wrote on mu list comment, I'm resolved a problem.
Thanks.
Stefano Errani
Hi Stefano,
I see a couple of problems with your code:
- Method should be patch and not post.
- I see that an invalid argument is returned, that could be because you are not adding the "person.metadata.sources.etag" field to the patch request.
PATCH /v1/resource_name:updateContact?updatePersonFields=emailAddresses HTTP/1.1
Body: {
"resourceName": "resource_name",
"etag": "etag",
"emailAddresses": [{ "value": "john.doe@gmail.com" }],
}
Host: people.googleapis.com
I must to know how can I do to make the PATCH method using java api library.
The example that I seen in
https://developers.google.com/people/v1/contacts#java_4
really update contact in GET mode ad the second snipped of code that I wrote in my post.
This is my code with etag:
service.people().updateContact("people/c3001613119211561864" person)
.setPersonFields("person.names,person.emailAddresses,person.addresses,person.phoneNumbers,person.urls,person.occupations,person.userDefined,person.metadata.sources.etag")
.execute();
same as the example.
But the result is
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
POST https://people.googleapis.com/v1/people/c3001613119211561864:updateContact?personFields=person.names...
{
"code": 400,
"errors": [
{
"domain": "global",
"message": "Request must set person.etag or person.metadata.sources.etag for the source that is being updated.",
"reason": "badRequest"
}
],
"message": "Request must set person.etag or person.metadata.sources.etag for the source that is being updated.",
"status": "INVALID_ARGUMENT"
}
The field .metadata.sources.etag is present and setted on person class.
I'm trying to instance the Person class as new class (person = new com.google.api.services.people.v1.model.Person();) and updateContact use POST method; if I instance the class in this way (person = service.people().get("people/c3001613119211561864").execute();)m the method is GET.
I don't know I can resolve the problem.
Best regards.
Stefano Errani
Good day.
I've tried to update contact with http connection (java.net.HttpURLConnection) using PATCH as request method and setting the json person manually, but I receive ProtocolException: Invalid HTTP method: PATCH.
At this point I don't know how can I resolve the problem.
Best regards.
Stefano Errani
Good day.
Trying various solutions and looking further on the various forums I understood the problem: when I get the Person class from the id I have to put the fields I want to extract as well:
person = service.people().get("people/c3001613119211561864").setPersonFields("names,emailAddresses,addresses,phoneNumbers,urls,occupations,userDefined").execute();
then I update the class and finally I update the contact on Google with:
service.people().updateContact(people/c3001613119211561864", person).setUpdatePersonFields(personFields).execute();
Best regards.
stefano Errani