首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >面对google people api格式的问题问题版本名称: people "googleapiclient.errors.UnknownApiNameOrVersion::v1“

面对google people api格式的问题问题版本名称: people "googleapiclient.errors.UnknownApiNameOrVersion::v1“
EN

Stack Overflow用户
提问于 2021-06-09 16:21:40
回答 1查看 38关注 0票数 1

我尝试使用people api (python)更新电子邮件地址。这是我的代码。请建议我使用正确的格式将电子邮件地址更新为现有联系人。

代码语言:javascript
运行
复制
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()

这是我的代码,你能纠正我吗?

代码语言:javascript
运行
复制
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()
EN

回答 1

Stack Overflow用户

发布于 2021-06-10 18:45:49

我已经用这个来修复了。而不是http。

代码语言:javascript
运行
复制
service = build('people', 'v1', credentials=creds)
service.people().updateContact(
        resourceName='people/XXXXXX', 
        updatePersonFields="emailAddresses", 
        body={"etag": "XXXXXXX", "emailAddresses": [{"value": "XXXX@gmail.com"}]}).execute()

参考资料:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67900262

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档