Go Back   Webmaster Forums UK SEO SEM Webmaster Community Forum - UKWW > Web Design and Website Development > Help and Tutorials for new Webmasters
Register FAQ Members List Downloads Calendar Today's Posts Webmaster Resources Webmaster Blogs
 
 

Help and Tutorials for new Webmasters Help and tutorials for people new to the Internet and webmastering in particular, there is no such thing as stupid question, please fell free to question about any aspects of webmastering you need help with.
Sub Forums::Content Management System ::Webmaster Toolbox

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2008, 11:22 AM
dman_2007
Guest
 
Posts: n/a
Default Tutorial : Adding data to Google Base

There are three ways using which you can your product listing to Google Base. They are :

1) One at a time

You can use web based listing adding tool provided at the Google Base itself to add one listing at a time. This way works best if you have only few product listings to add.

2) Data feed

Useful for adding a large number of products at once. You upload data feed file by using the browser itself or by connecting through ftp.

3) API

Most flexible way to add product listings. Yiou can code your current ecommerce platform to add product listing automatically to Google Base and to keep it synchonised.

I'll be concentrating on third way to add product listings. In my next post i'll show you how to do it.
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 09:01 AM
dman_2007
Guest
 
Posts: n/a
Default

Instead of creating the code from scratch to connect to Google Base service to perform basic operations and reinventing the wheel, we'll use Zend Framework's Gdata module. Zend framework comes with a demo script, which shows you how you can perform the basic operations. But the problem with the demo script is that it works with only a single demo item entry. Here's the script which you can use alongwith Zend framework, to perform basic operations easily :

Code:
<?php
  $old = ini_get('include_path');
  // windows users must use ';' instead of ':' in the line below
  ini_set('include_path', $old.':/path/to/ZendFramework/library/');
  
  require_once 'Zend/Loader.php';
  Zend_Loader::loadClass('Zend_Gdata_AuthSub');
  Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
  Zend_Loader::loadClass('Zend_Gdata_Gbase');
  
  function getClientLoginHttpClient($user, $pass) 
  {
    $service = Zend_Gdata_Gbase::AUTH_SERVICE_NAME;

    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
    return $client;
  }
  
  function insertItem($client, $itemInfo, $dryRun = false)
  {
    $service = new Zend_Gdata_Gbase($client);
    $newEntry = $service->newItemEntry();

    // Add title
    $newEntry->title = $service->newTitle(trim($itemInfo['title']));

    // Add some content
    $newEntry->content = $service->newContent($itemInfo['content']);
    $newEntry->content->type = $itemInfo['contentType'];

    
    $newEntry->itemType = $itemInfo['itemType'];
    $newEntry->itemType->type = $itemInfo['itemTypeType'];

    // Add item-specific attributes
    foreach($itemInfo['attributes'] as $attribute_name => $attribute_info)
    {
      $newEntry->addGbaseAttribute($attribute_name, $attribute_info['value'], $attribute_info['type']);
    }

    $createdEntry = $service->insertGbaseItem($newEntry, $dryRun);
    $itemUrl = $createdEntry->id->text;
    
    if(array_key_exists($itemInfo['media_attachments']))
    {
      $mediaFeed = $itemUrl . '/media/';
      
      foreach($itemInfo['media_attachments'] as $attachment)
      {
        $mediaFileSource = $service->newMediaFileSource('test.png');
        $mediaFileSource->setContentType('image/png');
        try 
        {
          $service->post($mediaFileSource, $mediaFeed); 
        } 
        catch (Zend_Gdata_App_Exception $e) 
        {
          var_dump($e);
        }
      }   
    }

    return $itemUrl;
  }

  function listAllMyItems($client) 
  {
    $service = new Zend_Gdata_Gbase($client);
    $feed = $service->getGbaseItemFeed();

    return $feed;
  }

  function updateItem($client, $itemUrl, $newItemInfo, $dryRun = false)
  {
    $service = new Zend_Gdata_Gbase($client);
    if($entry = $service->getGbaseItemEntry($itemUrl)) 
    {
      $entry->title   = $service->newTitle($newItemInfo['title']);
      $entry->content = $service->newContent($newItemInfo['content']);
      
      
      $baseAttributeArr = $entry->getGbaseAttribute('pages');
      if(is_object($baseAttributeArr[0])) 
      {
        $baseAttributeArr[0]->text = $newItemInfo['item_type'];
      }

      $baseAttributes = $entry->getGbaseAttributes();
      foreach($baseAttributes as $baseAttribute)
      {
        $aname = $baseAttribute->getName();
        if($aname != 'customer_id' && $aname != 'item_type')
        {
          $entry->removeGbaseAttribute($baseAttribute);
        }
      }

      foreach($newItemInfo['new_attributes'] as $attribute_name => $attribute_info)
      {
        $entry->addGbaseAttribute($attribute_name, $attribute_info['value'], $attribute_info['type']);  
      }
    
      try 
      {
        $entry->save($dryRun);
      } 
      catch (Zend_Gdata_App_Exception $e) 
      {
        echo "<div class='error'>ERROR:</div><br />\n";
        var_dump($e);
        return null;
      }
      
      if(array_key_exists($newItemInfo['media_attachments']))
      {
        $mediaFeed = $itemUrl . '/media/';
      
        foreach($itemInfo['media_attachments'] as $attachment)
        {
          $mediaFileSource = $service->newMediaFileSource($attachment['file_path']);
          $mediaFileSource->setContentType($attachment['file_type']);
          try 
          {
            $service->post($mediaFileSource, $mediaFeed); 
          } 
          catch (Zend_Gdata_App_Exception $e) 
          {
            var_dump($e);
          }
        }   
      } 
    } 
    else 
    {
      return null;
    }
    
    return true;
  }

  function deleteItem($client, $itemUrl, $dryRun = false) 
  {
    $service = new Zend_Gdata_Gbase($client);
    if ($entry = $service->getGbaseItemEntry($itemUrl)) 
    {
      try 
      {
        $entry->delete($dryRun);
      } 
      catch (Zend_Gdata_App_Exception $e) 
      {
        echo "<div class='error'>ERROR:</div><br />\n";
        var_dump($e); 
        return null;
      }
    } 
    else 
    {
      return null;
    }
  }
?>

Last edited by dman_2007; 04-18-2008 at 10:52 AM.
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 04-18-2008, 10:58 AM
dman_2007
Guest
 
Posts: n/a
Default

Now lets see what each of the function does :

1) insertItem

This function is used for inserting new item entry. First parameter passed is an authenticated http client obtained by using getClientLoginHttpClient function. Second parameter is an array called itemInfo which contains item entry info. Following elements are required to be present in itemInfo array : title, content, contentType, itemType and itemTypeType. Other useful array element is attributes element. attributes array element is an array itself containing list of attributes which is to be added in the item entry. Each element in attributes array with attribute name as key represent an attribute which is to be added and is an array itself. The attribute array contains two elements attribute_value and attribute_type. You can also specify media attchments by using media_attachments key in itemInfo array. Array element with media_attachments key is an array itself,w ith each of its element representing a separate attachment. Each attachment array element is an array itself, with file_path and file_type array elements. Final parameter is an indicator which indicates whether to actually perform the the operation or not.

2) listAllMyItems

This function is used for getting list of all the item entries currently prsent in a user's item feed. Only parameter passed to this function is an authenticated http client.

3) updateItem

This function used for updating any current item entry. itemUrl parameter is the url of the item entry to be updated and newItemInfo parameter contains the updated item entry info.

4) deleteItem

This function is used for deleting a currently existing item entry. itemUrl parameter specifes the current url of the item which is to be deleted.
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Webmaster Resources
 
The Forum Rules
Forum Rules - MUST READ
 
Site Of the Month
BizzFace
Nominate site of the month
 
Tag Cloud
affiliates article service article writer article writing blogging money blogs categories menu code content writer content writing services directories directory directory script e4 media group e4mediagroup.com ecommerce forum free submit godaddy godaddy codes godaddy coupon godaddy promo google home user iphone 3gs justdial clone keywords link optimization optimize the sites pages menu paid directories php right sidebar search engine script sell link seo total shop uk website yellow

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:36 PM.

UK Webmaster World Forums - Internet marketing, web development, domain names, SEO contest and discussuons.
Subscribe to our feeds   Subscribe to our feeds

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0