Gmail Contact List Importer
This is a smart API of GOOGLE which imports the contact list.This Contacts API allows developers to create, read, update, and delete contacts using the Google Data protocol, based on AtomPub.
var contactsService;
function setupContactsService() {
contactsService = new google.gdata.contacts.ContactsService(‘exampleCo-exampleApp-1.0′);
}
function logMeIn()
{
var scope = ‘http://www.google.com/m8/feeds’;
var token = google.accounts.user.login(scope);
}
/*
call this function during page load
*/
function initFunc() {
setupContactsService();
logMeIn();
}
/*
* Query for contacts
*/
// Create the contacts service object
function getMyContacts()
{
var contactsService =
new google.gdata.contacts.ContactsService(‘GoogleInc-jsguide-1.0′);
var contactAddressContainer = ”;
// The feed URI that is used for retrieving contacts
var feedUri = ‘http://www.google.com/m8/feeds/contacts/default/full’;
var query = new google.gdata.contacts.ContactQuery(feedUri);
// Set the maximum of the result set to be 50
query.setMaxResults(50);
var callback = function(result)
{
// An array of contact entries
var entries = result.feed.entry;
// Iterate through the array of contact entries
for (var i = 0; i < entries.length; i++)
{
var contactEntry = entries[i];
var emailAddresses = contactEntry.getEmailAddresses();
// Iterate through the array of emails belonging to a single contact entry
for (var j = 0; j < emailAddresses.length; j++)
{
var emailAddress = emailAddresses[j].getAddress();
//PRINT(‘email = ‘ + emailAddress);
contactAddressContainer += ‘<span style=”color:red;”>’+emailAddress+’</span><br/>’;
}
}
//creating a continer for holding contact list
document.getElementById(‘contact_holder’).innerHTML = contactAddressContainer;
}
// Submit the request using the contacts service object
contactsService.getContactFeed(query, callback, handleError);
}
// Error handler
var handleError = function(error)
{
alert(error);
}

Leave a Reply