I need to integrate my application with Google data API. Google team created the PHP client library, but as a part of ZendFramework.
I'm trying to use it as following:
- Extract everything into protected/vendors
- In the action I'm going to use ZF classes I do: Yii::import('application.vendors.Zend.*')
Then the code follows:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gbase');
Zend_Loader::loadClass('Zend_Uri_Http');
Zend_Loader::loadClass('Zend_Http_Client_Adapter_Socket');
Zend_Loader::loadClass('Zend_Gdata_Gbase_ItemEntry');
$serviceName = Zend_Gdata_Gbase::AUTH_SERVICE_NAME;
$user = Yii::app()->params['gBaseLogin'];
$pass = Yii::app()->params['gBasePassword'];
// Create an authenticated HTTP client
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $serviceName);
$serviceName = Zend_Gdata_Gbase::AUTH_SERVICE_NAME;
$user = Yii::app()->params['gBaseLogin'];
$pass = Yii::app()->params['gBasePassword'];
// Create an authenticated HTTP client
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $serviceName);
// Create an instance of the Base service
$service = new Zend_Gdata_Gbase($client);
//continue from here: http://www.zendframework.com/manual/en/zend.gdata.gbase.html
$i = 0;
$reader = Yii::app()->db->createCommand("SELECT p.* FROM Product p")->query();
if ($reader->rowCount > 0)
{
foreach ($reader as $p)
{
if ($i > 20) break;
$gProduct = $service->newItemEntry();
$gProduct->title = $service->newTitle($p['title']);
$gProduct->content = $service->newContent($p['description']);
$gProduct->content->type = 'text';
$gProduct->itemType = 'Products';
$gProduct->published = date('d/m/y H:i:s', strtotime($p['dtAdded']));
$gProduct->link = $service->newLink('http://everystyle.co.uk/womens/clothing/'.Utils::name2url($p['name']).'__'.$p['productID'].'.html');
// $gProduct->link = 'http://everystyle.co.uk/womens/clothing/'.Utils::name2url($p['name']).'__'.$p['productID'].'.html';
$gProduct->updated = empty($p['dtUpdated']) ? date('d/m/y H:i:s', strtotime($p['dtAdded'])) : date('d/m/y H:i:s', strtotime($p['dtUpdated']));
$gProduct->addGbaseAttribute('id', 'everystyle.co.uk-'.$p['productID'], 'text');
$gProduct->addGbaseAttribute('brand', $p['shop'], 'text');
$gProduct->addGbaseAttribute('color', $p['colourDesc'], 'text');
$gProduct->addGbaseAttribute('condition', 'New', 'text');
$gProduct->addGbaseAttribute('department', 'women's', 'text');
$gProduct->addGbaseAttribute('location', 'UK', 'text');
$gProduct->addGbaseAttribute('price', $p['price'].' GBP', 'floatUnit');
// $gProduct->addGbaseAttribute('product_type', $path, 'text');
$gProduct->addGbaseAttribute('quantity', $p['qty'], 'number');
if (!empty($sizeText))
$gProduct->addGbaseAttribute('size', $p['sizeText'], 'text');
$gProduct->addGbaseAttribute('year', date('Y', strtotime($p['dtAdded'])), 'number');
$gCreated = $service->insertGbaseItem($gProduct, true);
Yii::trace(print_r($gCreated, true));
$i++;
}
}
And it gives an error:
YiiBase::include(Zend_Gdata_Gbase_Extension_ItemEntry.php) [<a href='yiibase.include'>yiibase.include</a>]: failed to open stream: No such file or directory
Sure, that's OK - Yii doesn't know how to autoload Zend classes! It's quite strange, but there is no class here vendors/Zend/Gdata/Gbase/Extension/ItemEntry.php I double checked that - there is really no file there, neither in my distrib nor in Zend archives… I think, that enabling zend autoload will solve the problem.
The question is - how to enable Zend autoload? I remember there was a question like this regarding doctrine or propel. But I can't find that now.
Maybe someone has examples of such integration, maybe even google base examples?