media feed

2 messages Options
Embed this post
Permalink
michael.depetrillo

media feed

Reply Threaded More More options
Print post
Permalink
Is there a way to post binary attachments to the media feed for a google base entry?

I am having troubles using the gbase attribute image_link and would like post binary data instead. 

http://code.google.com/apis/base/starting-out.html#media_feed

--
Michael DePetrillo
[hidden email]
Mobile: (858) 761-1605
AIM: klassicd

www.michaeldepetrillo.com
Ryan Boyd-3

Re: media feed

Reply Threaded More More options
Print post
Permalink
Hi Michael,

Yes, this is possible -- though media support hasn't really been added into the Base component of the PHP client library.  Until that exists, you'll need to parse some links yourself and build what's called a MediaFileSource object yourself.

Code is below.  I've also added an issue in the issue tracker here:
http://framework.zend.com/issues/browse/ZF-2440

Here's the code:
?php

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gbase');

// Parameters for ClientAuth authentication
$service = Zend_Gdata_Gbase::AUTH_SERVICE_NAME;
$user = 'e-mail address';
$pass = 'password';

// Create an authenticated HTTP client
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);

// Create an instance of the Base service
$service = new Zend_Gdata_Gbase($client);

$feed = $service->getGbaseItemFeed();

// loop through all of my items and add a png image attachment
foreach ($feed as $entry) {
  echo $entry->title . "\n";
  $extEls = $entry->getExtensionElements();
  $mediaLinkHref = null;
  foreach ($extEls as $extEl) {
    if ($extEl->rootNamespaceURI == ' http://schemas.google.com/g/2005'
        && $extEl->rootElement == 'feedLink') {

        // this is a feedLink element
        $extAtts = $extEl->getExtensionAttributes();
        if ($extAtts['rel']['value'] == 'media') {
            $mediaLinkHref = $extAtts['href']['value'];
        }
    }
  }
  if ($mediaLinkHref != null) {
    echo "we have a media link href\n";
    echo "let's upload an image\n";
    $mediaFileSource = $service->newMediaFileSource('070528-020016.png');
    $mediaFileSource->setContentType('image/png');
    try {
      $service->post($mediaFileSource, $mediaLinkHref);
    } catch (Zend_Gdata_App_Exception $e) {
     var_dump($e);
    }
  }
}



On Jan 15, 2008 2:54 PM, Michael Depetrillo < [hidden email]> wrote:
Is there a way to post binary attachments to the media feed for a google base entry?

I am having troubles using the gbase attribute image_link and would like post binary data instead. 

http://code.google.com/apis/base/starting-out.html#media_feed

--
Michael DePetrillo
[hidden email]
Mobile: (858) 761-1605
AIM: klassicd

www.michaeldepetrillo.com