Creating shared contacts with python

190 views
Skip to first unread message

Tanay

unread,
Apr 12, 2011, 8:33:12 AM4/12/11
to Google Contacts, Shared Contacts and User Profiles APIs
here is a snippet of inerting a shared contact using python as in the
api documentation

new_contact = gdata.contacts.ContactEntry(title=atom.Title(text=name))
new_contact.content = atom.Content(text=notes)
# Create a work email address for the contact and use as primary.
new_contact.email.append(gdata.contacts.Email(address=primary_email,
primary='true', rel=gdata.contacts.REL_WORK))
# Add extended properties to add data which is used in your
application.
new_contact.extended_property.append(gdata.ExtendedProperty(
name='favourite flower', value='daisy'))
sports_property = gdata.ExtendedProperty(name='sports')
sports_property.SetXmlBlob('<dance><salsa/><ballroom_dancing/></
dance>')
new_contact.extended_property.append(sports_property)

# Send the contact data to the server.
contact_entry = gd_client.CreateContact(new_contact)


1) can phone number be inserted as well
2) what is the gdata object name for Phone number and the REL values.
where can we get a total list
3) Are the extended attributes shown in the google apps email contacts
(while browsing the contacts in the inbox contacts)
4) Any snippets for editing/eleting a contact?
The API doc says

new_name = raw_input('Enter a new name for the shared contact: ')
if not selected_entry.title:
selected_entry.title = atom.Title()
selected_entry.title.text = new_name
gd_client.UpdateContact(selected_entry.GetEditLink().href,
selected_entry)

//selected_entry.GetEditLink().h
how to browse through to reach to the selected_entry

Aaron

unread,
Apr 12, 2011, 2:04:42 PM4/12/11
to google-co...@googlegroups.com
I'm not sure how helpful this will be for you since I've mainly programmed against the Java API, so hopefully someone with experience implementing the Shared Contact API through Python will also respond, but I figured I would start off... In response to your questions:
  1. If the Python API is anything like the Java API inserting a phone number should be almost identical to the way that you inserted an email address in your example above. They have most of the same elements
  2. Here is a link describing the phone element and the possible REL values: http://code.google.com/apis/gdata/docs/2.0/elements.html#gdPhoneNumber
  3. From another forum describing extended property usage through the contacts web interface: http://www.google.com/support/forum/p/apps-apis/thread?tid=376c2e65e074b0c0&hl=en It looks like extended properties do not show up, but userDefiendFields will show up in the contact manager
  4. Since I don't have experience with the Python API I can't help here
Anyway, I hope this helps you a little bit.

ThatNateGuy

unread,
Apr 12, 2011, 2:08:23 PM4/12/11
to google-co...@googlegroups.com
Thanks, Tanay. I also wanted to bring it to your attention that the link to the code snippets for Python seem to be broken.

Reply all
Reply to author
Forward
0 new messages