/** * Check for thrown exceptions upon improper albumname/id setting */ public function testAlbumQueryExceptions() { $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser("sample.user"); try { $generatedString = $query->getQueryUrl(); } catch (Exception $e) { $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException); } $query->setAlbumId("1"); $query->setAlbumName("test"); try { $generatedString = $query->getQueryUrl(); } catch (Exception $e) { $this->assertTrue($e instanceof Zend_Gdata_App_InvalidArgumentException); } }
function getAlbum($user, $pass, $albumName) { $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service); $photos = new Zend_Gdata_Photos($client); $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser($user); $query->setAlbumName($albumName); $albumFeed = $photos->getAlbumFeed($query); $ret = array(); foreach ($albumFeed as $entry) { if ($entry instanceof Zend_Gdata_Photos_PhotoEntry) { $thumb = $entry->getMediaGroup()->getThumbnail(); $ret[] = array("url" => $thumb[1]->getUrl(), "id" => $entry->getGphotoId()); } } return $ret; }
/** * Retrieve list of gallery images and their properties * * @access public * @param string $gallery * @throws Exception * @return array $photoAttrs */ public function getGalleryImages($gallery) { $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser($this->getUser()); $query->setStartIndex(self::START_INDEX); $query->setMaxResults(self::MAX_RESULTS); if (Zend_Validate::is($gallery, 'Alnum')) { $query->setAlbumName($gallery); } elseif (Zend_Validate::is($gallery, 'Digits')) { $query->setAlbumId($gallery); } else { throw new Exception("Invalid gallery was given"); } try { $albumFeed = $this->getGphotoService()->getAlbumFeed($query); /* $previousLink = $albumFeed->getLink("previous"); $nextLink = $albumFeed->getLink("next"); if (!is_null($previousLink)) { $previousFeed = $this->getGphotoService()->getAlbumFeed($previousLink->href); $this->setPreviousLink($previousLink->href); } if (!is_null($nextLink)) { $nextFeed = $this->getGphotoService()->getAlbumFeed($nextLink->href); $this->setNextLink($nextLink->href); } */ $this->setGGalleryNumPhotos($albumFeed->getGphotoNumPhotos()); $this->setGGalleryLocation($albumFeed->getGphotoLocation()); $this->setGGalleryTimestamp(substr($albumFeed->getGphotoTimestamp(), 0, 10)); $this->setGGalleryTitle($albumFeed->title); foreach ($albumFeed as $photo) { $photoQuery = new Zend_Gdata_Photos_PhotoQuery(); $photoQuery->setUser($this->getUser()); if (Zend_Validate::is($gallery, 'Alnum')) { $photoQuery->setAlbumName($gallery); } elseif (Zend_Validate::is($gallery, 'Digits')) { $photoQuery->setAlbumId($gallery); } else { throw new Exception("Invalid gallery was given"); } $photoQuery->setPhotoId($photo->getGphotoId()); $photoQuery->setImgMax(self::PIXEL_MAX); $photoFeed = $this->getGphotoService()->getPhotoFeed($photoQuery); $geoRssWhere = empty($photo->getGeoRssWhere()->point->pos->text) ? "" : $photo->getGeoRssWhere()->point->pos->text; $gPicasa = new CW_Google_Picasa_Photo($photo->getGphotoId(), $photo->getGphotoCommentCount(), $photo->getGphotoCommentingEnabled(), $photoFeed->getGphotoSize(), $photoFeed->getGphotoTimestamp(), $photoFeed->mediaGroup->content[0]->url, $photoFeed->mediaGroup->description->text, $photoFeed->mediaGroup->thumbnail[0]->url, $photoFeed->mediaGroup->thumbnail[0]->width, $photoFeed->mediaGroup->thumbnail[0]->height, $geoRssWhere); $this->setPhotoAttrs($gPicasa); } } catch (Zend_Gdata_App_Exception $e) { print "Error: " . $e->__toString(); } catch (Zend_Gdata_App_HttpException $httpexception) { print $httpexception->getResponse()->getBody(); } catch (Exception $e) { print "Error: " . $e->__toString(); } return $this->getPhotoAttrs(); }