Example #1
0
 public function uploadPhoto($params)
 {
     $apiParams = $this->prepareApiParamsFromMapping('UploadPhoto');
     $mapping = $this->dataMapping['UploadPhoto'];
     $adapter = $this->getAdapter();
     $userId = $this->userId;
     $albumId = $this->albumId;
     $client = $adapter->getClient();
     $service = new \ZendGData\Photos($client);
     $fileSource = $service->newMediaFileSource($params['FullPath']);
     $fileSource->setContentType('image/' . $params['fileExtension']);
     $fileSource->setSlug($params['fileName']);
     $entry = $service->newPhotoEntry();
     $entry->setSummary($service->newSummary($params['description']));
     $entry->setTitle($service->newTitle($params['title']));
     $entry->setMediaSource($fileSource);
     $uri = "https://picasaweb.google.com/data/feed/api/user/{$userId}/albumid/{$albumId}";
     $data = $service->prepareRequest('POST', $albumId, null, $entry);
     $body = $data['data']->read($data['data']->getTotalSize());
     $client->setUri($uri);
     $client->setMethod('POST');
     $client->setRawBody($body);
     $client->setHeaders(array_merge(array('GData-Version' => '2', 'Authorization' => $client->getToken()->getParam('access_token'), 'Content-Type' => $data['contentType']), $data['headers']));
     $client->setParameterGet(array('alt' => 'json'));
     $adapter->setClient($client);
     $data = $adapter->getApiData();
     return $data;
 }
Example #2
0
<?php

require_once './autoloader.php';
$loader->registerNamespace('ZendGData\\', EVA_PUBLIC_PATH . '/../vendor/ZendGdata/library/ZendGData');
$user = "******";
$pass = "******";
$userId = '104171418568283484752';
$albumId = '5819073682310479025';
$client = \ZendGData\ClientLogin::getHttpClient($user, $pass, \ZendGData\Photos::AUTH_SERVICE_NAME);
$service = new \ZendGData\Photos($client);
$fileSource = $service->newMediaFileSource('D:\\xampp\\htdocs\\zf2\\public/static/upload\\e7\\6a\\b4\\YrYN3m.gif');
$fileSource->setContentType('image/jpeg');
$fileSource->setSlug('test.jpg');
$entry = new \ZendGData\Photos\PhotoEntry();
$entry->setMediaSource($fileSource);
$entry->setTitle($service->newTitle('test'));
$albumQuery = new \ZendGData\Photos\AlbumQuery();
$albumQuery->setUser($userId);
$albumQuery->setAlbumId($albumId);
$albumEntry = $service->getAlbumEntry($albumQuery);
try {
    $service->insertPhotoEntry($entry, $albumEntry->getEditLink()->getHref());
} catch (\Exception $e) {
    p($client);
    throw $e;
}
 private function getGooglePhotos()
 {
     $gAlbums = [];
     $cache = $this->getApcCache();
     $key = 'google_photos';
     if (!$cache->getItem($key)) {
         $client = $this->getGoogleClient();
         //        \Zend\Debug\Debug::dump($client);
         $gp = new \ZendGData\Photos($client);
         $userFeed = $gp->getUserFeed(self::GOOGLE_USER_ID);
         //        \Zend\Debug\Debug::dump($userFeed);
         foreach ($userFeed as $userEntry) {
             $albumId = $userEntry->getGphotoId()->getText();
             $gAlbums[$albumId]['label'] = $userEntry->getTitle()->getText();
             $query = $gp->newAlbumQuery();
             $query->setUser(self::GOOGLE_USER_ID);
             $query->setAlbumId($albumId);
             $albumFeed = $gp->getAlbumFeed($query);
             //            \Zend\Debug\Debug::dump($albumFeed);
             foreach ($albumFeed as $photoEntry) {
                 $photoId = $photoEntry->getGphotoId()->getText();
                 if ($photoEntry->getMediaGroup()->getContent() != null) {
                     $mediaContentArray = $photoEntry->getMediaGroup()->getContent();
                     $photoUrl = $mediaContentArray[0]->getUrl();
                 }
                 if ($photoEntry->getMediaGroup()->getThumbnail() != null) {
                     $mediaThumbnailArray = $photoEntry->getMediaGroup()->getThumbnail();
                     $thumbUrl = $mediaThumbnailArray[0]->getUrl();
                 }
                 $albumPhoto = array();
                 $albumPhoto['id'] = $photoId;
                 $albumPhoto['photoUrl'] = $photoUrl;
                 $albumPhoto['thumbUrl'] = $thumbUrl;
             }
             $gAlbums[$albumId]['photos'][] = $albumPhoto;
         }
         $cache->setItem($key, $gAlbums);
     } else {
         $gAlbums = $cache->getItem($key);
     }
     // Возвращение объединенного массива в представление для визуализации
     return $gAlbums;
 }