使用API​​创建Google共享联系人 - 联系人已创建,但不在共享目录中 [英] Creating a Google shared contact using the API - contact is created but not in the shared Directory

查看:166
本文介绍了使用API​​创建Google共享联系人 - 联系人已创建,但不在共享目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我的代码是

<$ p $!$ / $ / $ / $ / $ / $ / b $ / b $ / b $ / b $ b $ import $ at $数据

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)

printContact ID:%s%contact_entry.id.text

if __name__ =='__main__':
main()

我必须缺少一些相当简单的东西,但是看不到它是什么。



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



谢谢

Dave

解决方案

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

  feed_url = contacts_client.GetFeedUri(con​​tact_list = domain,projection ='full')

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

谢谢

戴夫


I'm currently using the shared_contacts_profiles.py script to load contacts from an external system into our Google Shared Domain contacts. I'd like to make the process more automated so I've tried to create a shared contact (with just a full name and email address) using a basic python script. The contact is created but it gets added to the administrator's contacts and not the Directory.

My code is

#!/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()

I must be missing something fairly simple, but just can't see what it is.

EDIT * I think that shared_contacts_profiles.py sets the domain contact list when it sends batches to Google. I wasn't going to use batches as there are only ever a couple of contacts to add. I also suspect I should be using gdata.contacts.service.ContactsService and not gdata.contacts.client.ContactsClient

Thanks

Dave

解决方案

In the end I used the original code as shown above with some additions. I needed to get the feed uri for the shared domain contact list and then supply that uri in the CreateContact.

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

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

Thanks

Dave

这篇关于使用API​​创建Google共享联系人 - 联系人已创建,但不在共享目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆