Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a google contact with python3

I would like to create a contact with the google api and python3

but gdata seemsnot to be compatible with python3. Like : AttributeError: 'function' object has no attribute 'func_name'

Does anyone have any sample that works on how to create contact with google api in python3 ?

thanks

like image 406
Bussiere Avatar asked Apr 28 '26 08:04

Bussiere


1 Answers

First, have you installed the gdata python client with pip, or with pip3? According to Google's repository, which says,

Python 3.3+ is also now supported! However, this library has not yet been > used as thoroughly with Python 3, so we'd recommend testing before deploying with Python 3 in production,

you can use pip3, like pip3 install google-api-python-client, to reinstall it. Once that's cleared up, see the below modified sample code-block for how to create a contact by just their Name, E-mail and Phone number with Python 3:

import atom.data
import gdata.data
import gdata.contacts.client
import gdata.contacts.data

gd_client = gdata.contacts.client.ContactsClient(source='YOUR_APPLICATION_NAME')

def create_contact(gd_client):
    new_contact = gdata.contacts.data.ContactEntry()

# Set the contact's name.
    new_contact.name = gdata.data.Name(
        given_name=gdata.data.GivenName(text='First'),
        family_name=gdata.data.FamilyName(text='Last'),
        full_name=gdata.data.FullName(text='Full'))
    new_contact.content = atom.data.Content(text='Notes')

# Set the contact's email addresses.
    new_contact.email.append(gdata.data.Email(address='[email protected]',\
        primary='true', rel=gdata.data.WORK_REL, display_name='E. Bennet'))
    new_contact.email.append(gdata.data.Email(address='[email protected]',\
        rel=gdata.data.HOME_REL))

# Set the contact's phone numbers.
    new_contact.phone_number.append(gdata.data.PhoneNumber(text='(206)555-1212',
        rel=gdata.data.WORK_REL, primary='true'))
    new_contact.phone_number.append(gdata.data.PhoneNumber(text='(206)555-1213',
        rel=gdata.data.HOME_REL))

# Send the contact data to the server.
    contact_entry = gd_client.CreateContact(new_contact)
    print ("Contact's ID: {}".format(contact_entry.id.text))
    return contact_entry
like image 109
Levi Maes Avatar answered May 01 '26 06:05

Levi Maes