google-code-export / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
1 stars 0 forks source link

Can't set Contacts full_name with GData-Version 3 #399

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. The python code

client = gdata.contacts.service.ContactsService(additional_headers = 
{'GData-Version': 3})
gdata.alt.appengine.run_on_appengine(client)

contact = gdata.contacts.ContactEntry()

if not hasattr(contact, 'title') or not contact.title:
    contact.title = atom.Title()
contact.title.text = "Full Name"

contact.name = gdata.data.Name(
    given_name=gdata.data.GivenName(text="Full Name"),
    full_name=gdata.data.FullName(text="Full Name")
)

contact.nickname = gdata.contacts.Nickname(text="Full Name")

contact_entry = client.CreateContact(contact)

What is the expected output? What do you see instead?

I expect to see the name field in the gmail contact UI. I only see the
nickname in the new contact.

Please provide any additional information below.
What version of the product are you using?
2.0.10

Please provide any additional information below.

contact_entry.ToString() returns the following xml code

<?xml version='1.0' encoding='UTF-8'?>
<ns0:entry ns1:etag="&quot;RnY7eDVSLyt7ImA9WxFUGUQJQwY.&quot;" 
xmlns:ns0="http://www.w3.org/2005/Atom" 
xmlns:ns1="http://schemas.google.com/g/2005">
    <ns0:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact" />
    <ns0:id>http://www.google.com/m8/feeds/contacts/my%40email.org/base/52f4b68e8b19834a</ns0:id>
    <ns0:updated>2010-07-01T14:10:27.800Z</ns0:updated>
    <ns0:title />
    <ns2:nickname xmlns:ns2="http://schemas.google.com/contact/2008">Full Name</ns2:nickname>
    <ns0:link href="https://www.google.com/m8/feeds/photos/media/my%40email.org/52f4b68e8b19834a" rel="http://schemas.google.com/contacts/2008/rel#photo" type="image/*" />
    <ns0:link href="https://www.google.com/m8/feeds/contacts/my%40email.org/full/52f4b68e8b19834a" rel="self" type="application/atom+xml" />
    <ns0:link href="https://www.google.com/m8/feeds/contacts/my%40email.org/full/52f4b68e8b19834a" rel="edit" type="application/atom+xml" />
    <ns2:edited xmlns:ns2="http://www.w3.org/2007/app">2010-07-01T14:10:27.800Z</ns2:edited>
</ns0:entry>

Original issue reported on code.google.com by Roman.Su...@gmail.com on 1 Jul 2010 at 2:17

GoogleCodeExporter commented 9 years ago
I wrote some code in gdata/contacts/__init__.py 

This python code sets full_name field in Contacts

    client = gdata.contacts.service.ContactsService(additional_headers = {'GData-Version': 3})
    gdata.alt.appengine.run_on_appengine(client)

    contact = gdata.contacts.ContactEntry()

    if not hasattr(contact, 'title') or not contact.title:
        contact.title = atom.Title()
    contact.title.text = "Full Name"

    contact.name = gdata.contacts.Name(
        given_name=gdata.contacts.GivenName(text="Full Name"),
        full_name=gdata.contacts.FullName(text="Full Name")
    )

    contact.nickname = gdata.contacts.Nickname(text="Full Name")

    contact_entry = client.CreateContact(contact)

contact_entry.ToString() returns the following xml code

<?xml version='1.0' encoding='UTF-8'?>
<ns0:entry ns1:etag=""RXs8ejVSLyt7ImA9WxFbEEoCRAQ."" 
xmlns:ns0="http://www.w3.org/2005/Atom" 
xmlns:ns1="http://schemas.google.com/g/2005">
<ns0:category scheme="http://schemas.google.com/g/2005#kind" 
term="http://schemas.google.com/contact/2008#contact" />
<ns0:id>http://www.google.com/m8/feeds/contacts/my%40email.org/base/4e57f470bcdf
ebd</ns0:id>
<ns0:updated>2010-07-02T13:45:04.572Z</ns0:updated><ns0:title>Full 
Name</ns0:title>
<ns2:nickname xmlns:ns2="http://schemas.google.com/contact/2008">Full 
Name</ns2:nickname>
<ns0:link 
href="https://www.google.com/m8/feeds/photos/media/my%40email.org/4e57f470bcdfeb
d" rel="http://schemas.google.com/contacts/2008/rel#photo" type="image/*" 
/><ns0:link 
href="https://www.google.com/m8/feeds/contacts/my%40email.org/full/4e57f470bcdfe
bd" rel="self" type="application/atom+xml" /><ns0:link 
href="https://www.google.com/m8/feeds/contacts/my%40email.org/full/4e57f470bcdfe
bd" rel="edit" type="application/atom+xml" />
<ns2:edited 
xmlns:ns2="http://www.w3.org/2007/app">2010-07-02T13:45:04.572Z</ns2:edited>
<ns1:name>
    <ns1:fullName>Full Name</ns1:fullName>
    <ns1:givenName>Full Name</ns1:givenName>
</ns1:name>
</ns0:entry>

Original comment by Roman.Su...@gmail.com on 2 Jul 2010 at 1:52

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by Roman.Su...@gmail.com on 5 Jul 2010 at 12:33

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you for posting your __init__.py.  I've been trying to write some code to 
do contact migration for our users when we go to Google Apps in a few months 
and hit a big stumbling block when I found I was unable to set the names of new 
contacts using GData-3.  When will these changes be included in the production 
code?

Original comment by keel...@gmail.com on 30 Nov 2010 at 7:05

GoogleCodeExporter commented 9 years ago
If you use the gdata.client and gdata.data, structured full names are supported 
there

Original comment by vi...@vinces.ca on 30 Nov 2010 at 7:12

GoogleCodeExporter commented 9 years ago
I could create the name object using gdata.data but when I would print out my 
contact with ToString() or try and upload the new contact to Google, the 
structured name information was not included in either.  Also when trying to 
put the full name in title with "contact.title=atom.Title(text='Firstname 
Lastname')", the title tag would be included in the ToString() output but it 
was not be included in the contact object returned by the server after 
uploading.  Updating my __init__.py with the above version is the only way I've 
had success setting a contact name for a new contact using gdata 2.0.13 with 
API version 3.

Original comment by keel...@gmail.com on 30 Nov 2010 at 7:26

GoogleCodeExporter commented 9 years ago
Here is what I am using: 

# gdata 2.0.12

import gdata
from gdata import contacts

client = contacts.client.ContactsClient()
client.client_login("user", "pass", "myAppNameAsSource")

new_contact = contacts.data.ContactEntry()

new_contact.name = gdata.data.Name(
                                   given_name=gdata.data.GivenName("Test"),                  
                                   family_name=gdata.data.FamilyName("Contact"),
                                  )

print new_contact.to_string(pretty_print=True)

contact = client.create_contact(new_contact)

print contact.to_string(pretty_print=True)

Original comment by vi...@vinces.ca on 30 Nov 2010 at 7:53

GoogleCodeExporter commented 9 years ago
Ahh, ok I'm using the contacts service rather than the client because I had 
trouble getting oauth to work with the client using the 
TwoLeggedOAuthExample.py sample in the source but oauth for the contacts 
service worked just fine for me.

Original comment by keel...@gmail.com on 30 Nov 2010 at 9:23

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Right yes, would require the ContactsClient using twolegged is simple enough

client = contacts.client.ContactsClient(source="MyApp")
client.auth_token = gdata.gauth.TwoLeggedOAuthHmacToken(consumer_key, 
consumer_secret, suername)

Original comment by vi...@vinces.ca on 30 Nov 2010 at 9:30

GoogleCodeExporter commented 9 years ago
When using either your code with oauth or the TwoLeggedOAuthExample.py found in 
gdata/src/samples/oauth (and after substituting a real username and my own 
consumer key and consumer secret, I get the following error (using gdata 
2.0.13):

Traceback (most recent call last):
  File "client-test.py", line 47, in ?
    PrintContacts(contacts_client)
  File "client-test.py", line 35, in PrintContacts
    feed = client.GetContacts()
  File "/usr/lib/python2.4/site-packages/gdata/contacts/client.py", line 194, in get_contacts
    desired_class=desired_class, **kwargs)
  File "/usr/lib/python2.4/site-packages/gdata/client.py", line 634, in get_feed
    converter=converter, desired_class=desired_class,
  File "/usr/lib/python2.4/site-packages/gdata/client.py", line 265, in request
    uri=uri, auth_token=auth_token, http_request=http_request, **kwargs)
  File "/home/cleary/google/atom/client.py", line 110, in request
    self.auth_token.modify_request(http_request)
  File "/usr/lib/python2.4/site-packages/gdata/gauth.py", line 1047, in modify_request
    return OAuthHmacToken.modify_request(self, http_request)
  File "/usr/lib/python2.4/site-packages/gdata/gauth.py", line 980, in modify_request
    token_secret=self.token_secret, verifier=self.verifier)
  File "/usr/lib/python2.4/site-packages/gdata/gauth.py", line 614, in generate_hmac_signature
    hashed = hmac.new(hash_key, base_string, hashlib.sha1)
  File "/usr/lib/python2.4/hmac.py", line 107, in new
    return HMAC(key, msg, digestmod)
  File "/usr/lib/python2.4/hmac.py", line 42, in __init__
    self.outer = digestmod.new()
AttributeError: 'builtin_function_or_method' object has no attribute 'new'

After running into that problem, I went with using the contacts service as the 
OAuth example worked without a hitch.

Original comment by keel...@gmail.com on 30 Nov 2010 at 9:37

GoogleCodeExporter commented 9 years ago
are you able to test that on python2.5, 2.4 is very old

Original comment by vi...@vinces.ca on 30 Nov 2010 at 9:45

GoogleCodeExporter commented 9 years ago
Please use the gdata.contacts.{client,data} modules.

Original comment by ala...@google.com on 7 Oct 2011 at 9:42