Creating a Google shared contact using the API - contact is created but not in the shared Directory

落花浮王杯 提交于 2019-12-11 04:45:51

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/17092077/creating-a-google-shared-contact-using-the-api-contact-is-created-but-not-in-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!