我尝试使用people api (python)更新电子邮件地址。这是我的代码。请建议我使用正确的格式将电子邮件地址更新为现有联系人。
service = discovery.build('people', 'v1', http=http, discoveryServiceUrl='https://people.googleapis.com/$discovery/rest:updateContact?updatePersonFields=emailAddresses')
service.people().updateContact(
resourceName=profileCode,
body={"resourceName": profileCode, "etag": accessToken},
updatePersonFields='test@gmail.com',
).execute()
这是我的代码,你能纠正我吗?
FLOW = OAuth2WebServerFlow(
client_id='1*****.apps.googleusercontent.com',
client_secret='Secret',
scope='https://www.googleapis.com/auth/contacts',
user_agent='contact_cms/YOUR_APPLICATION_VERSION')
def get_credentials(FLOW):
storage = Storage('info.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
credentials = tools.run_flow(FLOW, storage)
return credentials
def get_http(credentials):
http = httplib2.Http()
http = credentials.authorize(http)
return http
def update_a_google_contact(http):
profileCode = 'people/c3022811234561887053'
etag = '%EgU3AQI9abcdefMczZ1V0tVV1hubW89'
service = discovery.build('people', 'v1', http=http, discoveryServiceUrl='https://people.googleapis.com/$discovery/rest')
service.people().updateContact(
resourceName=profileCode,
body={"resourceName": profileCode, "etag": etag, "updatePersonFields=emailAddresses": [{ "value": "test@gmail.com" }]}
).execute()
def main():
creds=get_credentials(FLOW)
http=get_http(creds)
update_a_google_contact(http)
if __name__ == '__main__':
main()
发布于 2021-06-10 10:45:49
我已经用这个来修复了。而不是http。
service = build('people', 'v1', credentials=creds)
service.people().updateContact(
resourceName='people/XXXXXX',
updatePersonFields="emailAddresses",
body={"etag": "XXXXXXX", "emailAddresses": [{"value": "XXXX@gmail.com"}]}).execute()
参考资料:
https://stackoverflow.com/questions/67900262
复制