/** * @param array $params * @param array $queryParams * * @return \C2iS\SocialWall\Model\SocialItemResult */ protected function retrieveItemsFromWebservice(array $params = array(), array $queryParams = array()) { $queryParams['api_key'] = $this->apiKey; $url = sprintf('https://api.flickr.com/services/rest/?%s', http_build_query($queryParams)); $rsp = unserialize(file_get_contents($url)); $results = isset($rsp['photos']['photo']) && $rsp['photos']['photo'] ? $rsp['photos']['photo'] : array(); $socialItems = array(); foreach ($results as $item) { $socialItems[] = $this->createSocialItem($item); } $result = new SocialItemResult($socialItems); $result->setTotalItems($rsp['photos']['total']); $result->setPreviousPage($rsp['photos']['page'] - 1); $result->setNextPage($rsp['photos']['page'] + 1); return $result; }
/** * @param array $params * @param array $queryParams * * @return \C2iS\SocialWall\Model\SocialItemResult */ protected function retrieveItemsForTag(array $params = array(), array $queryParams = array()) { // Limit for youtube is maximum 50 (webservice limitation) $queryParams['maxResults'] = min(50, $queryParams['maxResults']); $service = new \Google_Service_YouTube($this->client); $results = $service->playlistItems->listPlaylistItems('id,contentDetails', $queryParams); $socialItems = array(); $videos = array(); /** @var \Google_Service_YouTube_PageInfo $pageInfo */ $pageInfo = $results->getPageInfo(); $nextPage = $results->getNextPageToken(); $prevPage = $results->getPrevPageToken(); /** @var \Google_Service_YouTube_PlaylistItem $item */ foreach ($results as $item) { /** @var \Google_Service_YouTube_PlaylistItemContentDetails $contentDetails */ $contentDetails = $item->getContentDetails(); $videos[] = $contentDetails->getVideoId(); } $results = $service->videos->listVideos('id,snippet,statistics', array('id' => implode(',', $videos))); /** @var \Google_Service_YouTube_Video $item */ foreach ($results->getItems() as $item) { $socialItems[] = $this->createSocialItem($item); } $result = new SocialItemResult($socialItems); $result->setNextPage($nextPage); $result->setPreviousPage($prevPage); $result->setTotalItems($pageInfo->getTotalResults()); return $result; }