def execute_batch_request(gd_client): # Feed that holds the batch request entries. request_feed = gdata.contacts.data.ContactsFeed() # Create a ContactEntry for the retrieve request. retrieve_contact = gdata.contacts.data.ContactEntry() retrieve_contact.id = atom.data.Id( text='https://www.google.com/m8/feeds/contacts/default/private/full/retrieveContactId') # Create a ContactEntry for the create request. create_contact = gdata.contacts.data.ContactEntry() create_contact.name = gdata.data.Name( full_name=gdata.data.FullName(text='Elizabeth Bennet'), given_name=gdata.data.GivenName(text='Elizabeth'), family_name=gdata.data.FamilyName(text='Bennet')) create_contact.email.append(gdata.data.Email(address='liz@gmail.com', primary='true', rel=gdata.data.HOME_REL)) # Retrieve the ContactEntry to update. update_contact = gd_client.GetContact('https://www.google.com/m8/feeds/contacts/default/full/updateContactId') update_contact.name.full_name = 'New Name' update_contact.name.given_name = 'New' update_contact.name.family_name = 'Name' # Retrieve the ContactEntry to delete. delete_contact = gd_client.GetContact('https://www.google.com/m8/feeds/contacts/default/full/deleteContactId') # Insert the entries to the batch feed. request_feed.AddQuery(entry=retrieve_contact, batch_id_string='retrieve') request_feed.AddInsert(entry=create_contact, batch_id_string='create') request_feed.AddUpdate(entry=update_contact, batch_id_string='update') request_feed.AddDelete(entry=delete_contact, batch_id_string='delete') # submit the batch request to the server. response_feed = gd_client.ExecuteBatch(request_feed, 'https://www.google.com/m8/feeds/contacts/default/full/batch') 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