Use of Google data services integrating Zend and Codeigniter


There’s another way to use Google Services integrating the Gdata part of Zend and CI This is made by the use of ‘hooks’. So, let’s start to explain how.

First of all, In CI config.php enable $config[‘enable_hooks’] = TRUE;

Then download the latest Zend Gdata part here:

Next, copy the library folder to your system/applications:

cp -Rf ZendGdata-[VERSION]/library/* system/applications/Gdata/

In system/applications/config edit your hooks.php and put this pre_controler action:

$hook['pre_controller'][] = array(
'class' => 'Gdata',
'function' => 'index',
'filename' => 'Gdata.php',
'filepath' => 'hooks'

Only one step more, put a file called Gdata.php in the hooks folder that contains this lines of code:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Gdata
  function index()
   ini_set('include_path',ini_get('include_path').':'.BASEPATH.'app/ Gdata');

So you have the Google Data services enabled to use from CI. An example to get all post from a blog, in controllers:

class Test extends Controller {
function Test() {
function index() {
$user = 'user'; // replace here with your data
$pass = 'passwd'; // replace here with your data
$service = 'blogger';
$BlogID = 'BlogID';
$client = Zend_GData_ClientLogin::getHttpClient($user, $pass, $service);
$gdClient = new Zend_Gdata($client);
$query = new Zend_Gdata_Query('');
$feed = $gdClient->getFeed($query);
$this->get_all_posts($gdClient, $BlogID);
function get_post($feed) {
// Let's start to retrieve the xml data
foreach ($feed->entries as $entry) {
echo "<h1>" . $entry->title->text . "</h1><br>\n";
echo "<p>" . $entry->content->text . "</p><hr>\n";
function get_all_posts($gdClient, $BlogID) {
$query = new Zend_Gdata_Query('' . $BlogID . '/posts/default');
$feed = $gdClient->getFeed($query);

P.S: Only one more thing. In Zend App.php line 815 there’s a line that instance a name of class Zend_Gdata_Feed that doesn’t exists, replace or debug why, the right class is Zend_Gdata_App_Feed.

No hay contenido relacionado