Codeigniter, API, Web-service, PHP, jQuery, MySQL
Google has vast number of API’s. Among them Google Contacts API is one of them. Recently i have to work with this API including Codeigniter. But there is very limited number of post which describes everything very clearly. Therefore as i worked with this one, i am sharing my knowledge here.
Tools that i used:
What will be done:
A. Import Contacts from a Google Account
First of all, add the Zend Library folder in codeigniter libraries folder. Create a library file in codeigniter/library folder called Zend.php. Put the following contents into the file:
<?php if (!defined('BASEPATH')) {exit('No direct script access allowed');}
class Zend
{
/**
* Include the Zend library once
* we load the zend Library class
*
* @param none
* @return none
*/
function __construct(){
ini_set('include_path',
ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries');
}
/**
* Load Zend Library
*
* @param string $class
* @return object $class
*/
function load($class){
require_once (string) $class . EXT;
}
}
/* End of Zend.php */
Then we need a Existing Google Email account User Name and Password. We will pass the parameter through our controller methods. Inside the method we will load the library Zend.php. Then using this library we will load the Zend Gdata Library for importing the Contacts using Google API’s.
Have a look on the following code:
/**
* Import Contacts using Zend Library
*
* @access private
* @param string $accountUserName
* @param string $accountPassword
* @return none
*/
private function _importContacts($accountUserName, $accountPassword){
$this->load->library('zend');
$this->zend->load('Zend/Loader');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');
try{
//perform account login and set protocol version
$client = Zend_Gdata_ClientLogin::getHttpClient($accountUserName, $accountPassword, 'cp');
$gData = new Zend_Gdata( $client );
$gData->setMajorProtocolVersion(3);
//perform query and get result from feed
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');
$query->startIndex = 0;
$query->maxResults = 25;
$query->setParam('orderby', 'lastmodified');
$query->setParam('sortorder', 'descending');
$feed = $gData->getFeed($query);
$this->data['AccountTitle'] = $feed->title;
$this->data['currentNumber'] = 25;
$this->data['TotalResults'] = $feed->totalResults;
$this->data['contactList'] = $this->_processFeedResult($feed);
}catch(Exception $e){
die('Error: ' . $e->getMessage());
}
}
Comming soon…
Codeginter Expert. Beside Codeigniter, my expertise includes Zend Framework, jQury, CSS/XHTML, API's, Web-service etc.
4 Responses to Google Contact’s API with Codeigniter Framework [part-01]
programy do sciagania za darmo
March 25th, 2011 at 1:16 pm
Very interesting, thanks a lot!
bizuteria swarovski
March 25th, 2011 at 10:17 pm
Interesting, thanks for your effort!
darmowe gry na telefon
March 27th, 2011 at 7:54 am
Very interesting, thanks a lot!
sesli chat
April 5th, 2011 at 9:49 pm
I used to be more than happy to find this web-site.I wanted to thanks for your time for this excellent read!! I undoubtedly enjoying every little little bit of it and I have you bookmarked to check out new stuff you blog post.