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; }
<?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; }