I'm trying to get a list of contacts from google's API, and then update some of them. While running the updateContact
function I get 403 error Request person.etag is different than the current person.etag. Clear local cache and get the latest person."
every time.
I'm reading the contact's etag using this code:
service = build('people', 'v1', credentials=creds)
results = service.people().connections().list(
resourceName='people/me',
pageSize=100,
personFields='names,emailAddresses').execute()
connections = results.get('connections', [])
Then for each contact
in the connections
, Im trying yo change the contact givenName and familyName:
service.people().updateContact(resourceName="contact's resource name",
updatePersonFields="names",
body={
"etag": "contact's etag",
"names": [
{
"familyName": "new family name",
"givenName": "new given name"
}
]
}
).execute()
The contact's etag
and resourceName
are taken from the connection's list response.
for example:
print(connections[0])
{'resourceName': 'people/<resource_number>',
'etag': 'etag string',
'names': [{'metadata': {'primary': True,
'source': {'type': 'CONTACT', 'id': 'id number'}},
'displayName': 'x',
'familyName': 'x',
'givenName': 'x',
'displayNameLastFirst': 'x',
'unstructuredName': 'x'}]}
question from:
https://stackoverflow.com/questions/65842428/googleapiclient-in-python-using-updatecontact-returns-403 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…