Here's some example code:

import atom
import gdata.contacts
import gdata.contacts.service
import gdata.contacts.data
import gdata.data

gd_client = gdata.contacts.service.ContactsService()
gd_client.email = 'MYEMAIL'
gd_client.password = 'MYPASSWORD'
gd_client.source = 'test'
gd_client.ProgrammaticLogin()

name="Test Person"
primary_email="[email protected]"

new_contact = gdata.contacts.ContactEntry(title=atom.Title(text=name))
new_contact.email.append(gdata.contacts.Email(address=primary_email, 
primary='true', rel=gdata.contacts.REL_WORK))
new_contact.phone_number.append(gdata.contacts.PhoneNumber("650-555-5555", 
primary='true'))
new_contact.structured_postal_address.append(gdata.data.StructuredPostalAddress(rel=gdata.data.WORK_REL,
 
primary='true',
    street=gdata.data.Street(text='1600 Amphitheatre Pkwy'),
    city=gdata.data.City(text='Mountain View'),
    region=gdata.data.Region(text='CA'),
    postcode=gdata.data.Postcode(text='94043'),
    country=gdata.data.Country(text='United States')))

contact_entry = gd_client.CreateContact(new_contact)

--

and this is the error it gives me:

C:\Python27\python.exe C:/Users/gbroiles/Projects/google-contacts/c4.py
Traceback (most recent call last):
  File "C:/Users/gbroiles/Projects/google-contacts/c4.py", line 26, in 
<module>
    contact_entry = gd_client.CreateContact(new_contact)
  File "C:\Python27\lib\site-packages\gdata\contacts\service.py", line 132, 
in CreateContact
    converter=gdata.contacts.ContactEntryFromString)
  File "C:\Python27\lib\site-packages\gdata\service.py", line 1236, in Post
    media_source=media_source, converter=converter)
  File "C:\Python27\lib\site-packages\gdata\service.py", line 1322, in 
PostOrPut
    headers=extra_headers, url_params=url_params)
  File "C:\Python27\lib\site-packages\atom\__init__.py", line 93, in 
optional_warn_function
    return f(*args, **kwargs)
  File "C:\Python27\lib\site-packages\atom\service.py", line 176, in request
    content_length = CalculateDataLength(data)
  File "C:\Python27\lib\site-packages\atom\service.py", line 736, in 
CalculateDataLength
    return len(str(data))
  File "C:\Python27\lib\site-packages\atom\__init__.py", line 377, in 
__str__
    return self.ToString()
  File "C:\Python27\lib\site-packages\atom\__init__.py", line 374, in 
ToString
    return ElementTree.tostring(self._ToElementTree(), 
encoding=string_encoding)
  File "C:\Python27\lib\site-packages\atom\__init__.py", line 369, in 
_ToElementTree
    self._AddMembersToElementTree(new_tree)
  File "C:\Python27\lib\site-packages\atom\__init__.py", line 329, in 
_AddMembersToElementTree
    instance._BecomeChildElement(tree)
AttributeError: 'StructuredPostalAddress' object has no attribute 
'_BecomeChildElement'

--

the problem seems to be in the StructuredPostalAddress part, but I can't 
seem to figure out what it doesn't like. The example runs fine if I comment 
out the address lines - but I would like to store addresses for my 
contacts, surprisingly enough. 

Any ideas?

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html

Reply via email to