9 messages in com.googlegroups.google-base-data-apiRe: sample Products insert with php5 ...| From | Sent On | Attachments |
|---|---|---|
| sant...@gmail.com | 20 Aug 2007 11:34 | |
| Jeff S | 27 Aug 2007 13:30 | |
| sant...@gmail.com | 27 Aug 2007 17:26 | |
| Jeff S | 05 Sep 2007 17:01 | |
| sant...@gmail.com | 06 Sep 2007 22:19 | |
| Jeff S | 10 Sep 2007 18:09 | |
| sant...@gmail.com | 10 Sep 2007 23:22 | |
| Chuender | 12 Sep 2007 08:46 | |
| Jeff S | 12 Sep 2007 09:48 |
| Subject: | Re: sample Products insert with php5 code![]() |
|---|---|
| From: | sant...@gmail.com (sant...@gmail.com) |
| Date: | 09/06/2007 10:19:30 PM |
| List: | com.googlegroups.google-base-data-api |
Thanks again Jeff!
Only thing I'm hanging on now - and I don't understand at all, is why I can't get to set these two attributes: expiration_date, and image_link,
just as for the others, I'm doing: addBaseAttribute('image_link', ''.$image_link.'', $entry); addBaseAttribute('expiration_date', ''.$expiration_date.'', $entry);
in reply I get: Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400' in /vhost/home/sultane/ sultaneantiques.com/var/www/html/newweb/masterdb/froogle/ ZendGdata-1.0.1/library/Zend/Gdata/App.php5:432 Stack trace: #0 /vhost/home/sultane/sultaneantiques.com/var/www/html/newweb/ masterdb/froogle/ZendGdata-1.0.1/library/Zend/Gdata/App.php5(606): Zend_Gdata_App->post('<atom:entry xml...', 'http://www.goog...') #1 /vhost/home/sultane/sultaneantiques.com/var/www/html/newweb/ masterdb/froogle/sample.php5(59): Zend_Gdata_App-
insertEntry(Object(Zend_Gdata_Entry), 'http://www.goog...')
#2 {main} thrown in /vhost/home/sultane/sultaneantiques.com/var/www/html/ newweb/masterdb/froogle/ZendGdata-1.0.1/library/Zend/Gdata/App.php5 on line 432
how do I add the expiration date and the item image link?
Thank you,
On Sep 5, 8:01 pm, Jeff S <j....@google.com> wrote:
On Aug 27, 5:26 pm, "sant...@gmail.com" <sant...@gmail.com> wrote:
Hi! Thank you so much!
Could you also complete this example with: -listing items
Sure! To list items, you can query the items feed for your own items or the snippets feed. You get a feed object back from the server an you can access the entries like this:
$query = new Zend_Gdata_Query('http://www.google.com/base/feeds/ items'); $feed = $gdClient->getFeed($query);
$feed->entries[0]->title->text; $feed->entries[0]->content->text;
Since the Google Base attributes are stored as extension elements, I wrote a function to find a specific attribute element in the Google Base namespace.
function getBaseAttribute($name, $entry) { $matches = array(); foreach($entry->getExtensionElements() as $element) { if($element->rootElement == $name && $element->rootNamespaceURI == 'http://base.google.com/ns/1.0') { $matches[count($matches)] = $element; } } return $matches;
}
You can use it like this:
$item_type_matches = getBaseAttribute('item_type', $feed->entries[0]); $item_type_matches[0]->text
-delete an item or bulk
Deleting an item should be a bit easier. You can just call delete on an entry from your items feed like this:
$createdItem->delete();
Questions, as always, are welcome.
Thank you,
Jeff
That would make for a complete php5 example using Products (instead of recipes.. :P) which would be helpful to many!
Much appreciated!
Best,
On Aug 27, 4:30 pm, Jeff S <j....@google.com> wrote:
Hello,
There is a slightly out of date sample which shows how to insert a
recipe using an older version of the Zend Gdata client library. You
can see the recipes example
here:http://code.google.com/apis/base/samples/php/php-sample-zend.html
I've written a simple test script which you should get you started in creating products with the latest version of the Zend library. See below:
<?php
require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Http_Client'); Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_Query'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_App_Extension_Element');
function addBaseAttribute($name, $value, $entry) { $array = $entry->getExtensionElements(); $new_extension = new Zend_Gdata_App_Extension_Element($name, 'g', 'http://base.google.com/ns/1.0', $value); $array[count($array)] = $new_extension; $entry->setExtensionElements($array);
}
$user = 'replace'; $pass = 'replace';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'gbase'); $gdClient = new Zend_Gdata($httpClient);
$entry = $gdClient->newEntry(); $entry->title = $gdClient->newTitle(trim('My computer')); $entry->content = $gdClient->newContent(trim('It is new and improved.')); $entry->content->setType('text'); addBaseAttribute('item_type', 'products', $entry);
$createdItem = $gdClient->insertEntry($entry, 'http://www.google.com/ base/feeds/items?dry-run=true');
print 'Created: '; print $createdItem->title->text; print '<br/>Created Id: '; print $createdItem->id->text;
?>
Happy coding,
Jeff
Hi! does anyone have sample code in php5 for inserting Products items? Best Regards,




