Webmaster Forum
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

UK Web Hosting
UK Web Hosting
Website Hosting
Website Hosting
UK One Way
UK One Way
Free Website Thumbnail Creator
 
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2008, 01:22 PM
dman_2007
Guest
 
Posts: n/a
iTrader: / %
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, 11:01 AM
dman_2007
Guest
 
Posts: n/a
iTrader: / %
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 12:52 PM.
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 04-18-2008, 12:58 PM
dman_2007
Guest
 
Posts: n/a
iTrader: / %
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

Webmaster Resources
UK Web Hosting
UK WW SEO Tools
Free site submission
Web Directory
 
Advertisement
Get top 10 exposure
 
Site Of the Month
BizzFace
Nominate site of the month
 
Tag Cloud
2 column 2 columns 301 addtype beauty bid bidding directory blog post british telecom broadband cheap community dedicated hosting directory directory network domain name ecommerce ecommerce information ecommerce poll edegra fibre optic fragrance fraud free free portal script generate revenue generic viagra google google serps graphics heaven htaccess intel internet spending james in london kamagra keywords layout link exchange links wanted linux and windows server local search managed hosting modeling online retail online spending optimising owg in london parking perfume photography php picture of the day purple rss scripts search engine search quality skincare special discount speed cameras subdomain settup submission theme the planet usability web hosting website win a network wordpress

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 07:08 AM.

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 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150