Contacts are stored in the user's Google Account; most Google services have access to the contact list. The details of the authorization process, or "flow," for OAuth 2.0 vary somewhat depending on what kind of application you're writing. It allows a user to request a set of contact groups that match specified criteria, such as requesting contact groups updated after a given date. Title(text='Salsa group') create_group.extended_property.append( Extended Property(name='more info about the group', value='Nice people') # Retrieve the Group Entry to update. Get Group('https:// Contact Group Id') update_group.= 'New Group Title' update_group.= 'New Group Content' # Retrieve the Group Entry to delete. Get Group('https:// Contact Group Id') # Insert the entries to the batch feed. Add Query(entry=retrieve_group, batch_id_string='retrieve') request_feed. Add Insert(entry=create_group, batch_id_string='create') request_feed. Add Update(entry=update_group, batch_id_string='update') request_feed. Add Delete(entry=delete_group, batch_id_string='delete') # submit the batch request to the server.
Your client application can use the Google Contacts API to create new contacts, edit or delete existing contacts, and query for contacts that match particular criteria This document is intended for programmers who want to write client applications that can interact with Google's contact lists. The following general process applies to all application types: If your public application uses scopes that permit access to certain user data, it must pass review. For example, to send a date-range query, add the def print_date_min_query_results(gd_client, start_time): query = gdata.service. Id( text='https:// Contact Group Id') # Create a Group Entry for the create request.
It provides a series of examples of basic API interactions. If you see unverified app on the screen when testing your application, you must submit a verification request to remove it. Full Name(text='Elizabeth Bennet')) new_contact.content = Content(text='Notes') # Set the contact's email addresses. Email(address='[email protected]', primary='true', rel= Query(feed='/m8/feeds/groups/default/full') query.updated_min = start_time feed = gd_client. Get Contact('https:// Contact Id') update_full_name = 'New Name' update_given_name = 'New' update_family_name = 'Name' # Retrieve the Contact Entry to delete. Get Contact('https:// Contact Id') # Insert the entries to the batch feed. Add Query(entry=retrieve_contact, batch_id_string='retrieve') request_feed. Add Insert(entry=create_contact, batch_id_string='create') request_feed. Add Update(entry=update_contact, batch_id_string='update') request_feed. Add Delete(entry=delete_contact, batch_id_string='delete') # submit the batch request to the server. Execute Batch(request_feed, 'https:// for entry in response_feed.entry: print '%s: %s (%s)' % (entry.batch_id.text, entry.batch_status.code, entry.batch_status.reason) return response_feed def execute_batch_request(gd_client): # Feed that holds the batch request entries. Groups Feed() # Create a Group Entry for the retrieve request.
Elements generated by the API are shown in bold in the output. def Print All Contacts(gd_client): feed = gd_client. For general Google Contacts API reference information, see the reference guide. Here's the OAuth 2.0 scope information for the Google Contacts API: To request access using OAuth 2.0, your application needs the scope information, as well as information that Google supplies during application registration (such as the client ID and/or the client secret). Create Group(new_group) print "Contact group's Atom Id: %s" % created_text return created_group def create_contact_group(gd_client): new_group = gdata. Title(text='Salsa group')) new_group.extended_properties.append( Extended Property(name='more info about the group', value='Nice people.')) created_group = gd_client. pass If you're performing a lot of operations, the time it takes to send and receive all those HTTP messages can really add up, making your app slow and unresponsive. Family Name(text='Bennet')) create_contact.email.append( Email(address='[email protected]', primary='true', rel= This section contains some information to help you get started with the Google Contacts API. If you already have a test account with a project registered in the API Console, then you're all set; you can visit the Google Contacts API user interface to set up, edit, or view your test data. Contacts Service my Service = new Contacts Service("YOUR_APPLICATION_NAME"); // Authorize the service object. The Google APIs client libraries can handle some of the authorization process for you. Create Group(new_group) print "Contact group's Atom Id: %s" % created_text return created_group def delete_contact_group(gd_client, contact_group_url): # Retrieving the contact group is required in order to get the Etag. With batch requests you can have the server perform multiple operations with a single HTTP request. Get Xml Blob() print ' Extended Property - %s: %s' % (extended_property.name, value) status code and a feed containing any contacts that were created or updated after the date specified.
The Contacts Data API supports query parameters described in the Contacts Data API Reference print_datemin_query_results(gd_client): updated_min = '2008-01-01' query = gdata.contacts.client.
WORK_REL, primary='true')) new_contact.phone_number.append( pass def update_contact_photo(gd_client, contact_url): contact = gd_client. Get Groups() for entry in feed.entry: print 'Atom Id: %s' % text print 'Group Name: %s' % group.print 'Last Updated: %s' % group.print 'Extended Properties:' for extended_property in entry.extended_property: if extended_property.value: value = extended_property.value else: value = extended_property.
pass return None def delete_contact(gd_client, contact_url): # Retrieving the contact is required in order to get the Etag. Get Contact(contact_url) hosted_image_binary = gd_client. Get Photo(contact_entry) image_file = open('test.jpg', 'wb') image_file.write(hosted_image_binary) image_file.close() def update_contact_photo(gd_client, contact_url, media_object): contact = gd_client. Change Photo(media_object, contact) except gdata.client. Request Error, e: if e.status == 412: # Etags mismatch: handle the exception. Request Error, e: if e.status == 412: # Etags mismatch: handle the exception. * The contact-group entry representing a system group doesn't contain a System groups' names are not guaranteed to be localized, so in general your client is responsible for presenting the system groups in a way appropriate for your users, such as by providing localized names for the system groups, or representing them using Print All Groups(gd_client): feed = gd_client.
for group in entry.group_membership_info: print ' Member of group: %s' % (group.href) # Display extended properties.
for extended_property in entry.extended_property: if extended_property.value: value = extended_property.value else: value = extended_property.
Each of those fields let applications store data in 2 flavors: If only one of the flavors is provided, the API uses heuristic parsers to generate the missing flavor using the provided data.