Skip to content

Instantly share code, notes, and snippets.

@yaroslav-ilin
Created January 30, 2012 20:32
Show Gist options
  • Save yaroslav-ilin/1706499 to your computer and use it in GitHub Desktop.
Save yaroslav-ilin/1706499 to your computer and use it in GitHub Desktop.
Google Picasa Web Albums read only API PHP Parser
// Google Picasa Web Albums read only API PHP Parser
// © 2010 inst (http://www.inst.tk/)
function picasa_list_pictures( $user, $album, $thumb_max_size = 200 )
{
$feed_url = "http://picasaweb.google.com/data/feed/base/user/$user/album/$album";
$xml = new DOMDocument();
$xml->load( $feed_url );
$namespace_media = $xml->getElementsByTagName( 'feed' )->item( 0 )->getAttribute( 'xmlns:media' );
$pictures = array();
foreach( $xml->getElementsByTagName( 'entry' ) as $entry )
{
$elem = $entry->getElementsByTagNameNS( $namespace_media, 'group' )->item( 0 );
$thumb = array( 'url' => '', 'size' => 0 );
foreach( $elem->getElementsByTagNameNS( $namespace_media, 'thumbnail' ) as $xml_thumb )
{
$thumb_size = (int)$xml_thumb->getAttribute( 'height' );
$thumb_width = (int)$xml_thumb->getAttribute( 'width' );
if ( $thumb_width < $thumb_size ) $thumb_size = $thumb_width;
if( $thumb_size < $thumb_max_size && $thumb_size > $thumb['size'] )
{
$thumb['url'] = $xml_thumb->getAttribute( 'url' );
$thumb['size'] = $thumb_size;
}
}
$content_tag = $elem->getElementsByTagNameNS( $namespace_media, 'content' )->item( 0 );
$picture = array(
'title' => $elem->getElementsByTagNameNS( $namespace_media, 'title' )->item( 0 )->nodeValue,
'thumbnail' => $thumb['url'],
'url' => $content_tag->getAttribute( 'url' ),
'width' => $content_tag->getAttribute( 'width' ),
'height' => $content_tag->getAttribute( 'height' ),
'mimetype' => $content_tag->getAttribute( 'type' )
);
$keywords = $elem->getElementsByTagNameNS( $namespace_media, 'keywords' )->item( 0 )->nodeValue;
if ( isset( $keywords{0} ) )
foreach( explode( ',', $keywords ) as $keyword )
$picture['keywords'][]= trim( $keyword );
$pictures []= $picture;
}
return $pictures;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment