gpt4 book ai didi

python - 使用 API 创建 Google 共享联系人 - 联系人已创建,但不在共享目录中

转载 作者:太空宇宙 更新时间:2023-11-03 18:56:50 24 4
gpt4 key购买 nike

我目前正在使用 shared_contacts_profiles.py用于将外部系统中的联系人加载到我们的 Google 共享域联系人中的脚本。我想让这个过程更加自动化,所以我尝试使用基本的 python 脚本创建一个共享联系人(只有全名和电子邮件地址)。联系人已创建,但会添加到管理员的联系人中,而不是目录中。

我的代码是

#!/usr/bin/python
import atom
import gdata.data
import gdata.contacts.client
import gdata.contacts.data

def main():

admin_email = 'admin@mydomain.com'
admin_password = 'P4ssw0rd'
domain_index = admin_email.find('@')
domain = admin_email[domain_index+1:]

contacts_client = gdata.contacts.client.ContactsClient(domain=domain)
contacts_client.client_login(email=admin_email,
password=admin_password,
source='shared_contacts_profiles',
account_type='HOSTED')

new_contact = gdata.contacts.data.ContactEntry()
new_contact.name = gdata.data.Name(
full_name=gdata.data.FullName(text='John Doe'))
new_contact.email.append(gdata.data.Email(address='john.doe@example.com',
primary='true',rel=gdata.data.WORK_REL))
contact_entry = contacts_client.CreateContact(new_contact)

print "Contact's ID: %s" % contact_entry.id.text

if __name__ == '__main__':
main()

我一定错过了一些相当简单的东西,但只是看不出它是什么。

编辑*我认为shared_contacts_profiles.py在向Google批量发送时设置域联系人列表。我不打算使用批处理,因为只需添加几个联系人。我还怀疑我应该使用 gdata.contacts.service.ContactsService 而不是 gdata.contacts.client.ContactsClient

谢谢

戴夫

最佳答案

最后我使用了如上所示的原始代码并添加了一些内容。我需要获取共享域联系人列表的 feed uri,然后在 CreateContact 中提供该 uri。

feed_url = contacts_client.GetFeedUri(contact_list=domain, projection='full')

contact_entry = contacts_client.CreateContact(new_contact,insert_uri=feed_url)

谢谢

戴夫

关于python - 使用 API 创建 Google 共享联系人 - 联系人已创建,但不在共享目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17092077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com