/** * @param array $params * @param array $queryParams * * @return SocialItemResult */ protected function retrieveItemsForUser(array $params = array(), array $queryParams = array()) { $service = new \Google_Service_Plus($this->client); $results = $service->activities->listActivities(sprintf('+%s', $params['user_id']), 'public', $queryParams); $socialItems = array(); /** @var \Google_Service_Plus_Activity $item */ foreach ($results->getItems() as $item) { $socialItems[] = $this->createSocialItem($item); } $result = new SocialItemResult($socialItems); $result->setNextPage($results->getNextPageToken()); return $result; }
/** * @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 * * @throws Exception\InvalidFacebookParametersException * @return SocialItemResult */ protected function retrieveItemsForUser(array $params = array(), array $queryParams = array()) { if (isset($queryParams['limit'])) { $queryParams['limit'] = min($queryParams['limit'], 40); } $request = new \Facebook\FacebookRequest($this->session, 'GET', sprintf('/%s/posts?%s', $params['user_id'], http_build_query(array_merge(array('fields' => 'privacy,message,link,name,status_type,likes,comments,type,created_time,updated_time,from,attachments', 'summary' => 'true'), $queryParams)))); $client = $request->getHttpClientHandler(); $client->addRequestHeader('Accept-Language', 'fr-FR,fr;q=0.8'); $request->setHttpClientHandler($client); $response = $request->execute(); $results = isset($response->getResponse()->data) ? $response->getResponse()->data : array(); $socialItems = array(); foreach ($results as $item) { $socialItems[] = $this->createSocialItem($item); } $result = new SocialItemResult($socialItems); $result->setPreviousPage($response->getResponse()->paging->previous); $result->setNextPage($response->getResponse()->paging->next); 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; }
/** * @param array $params * @param array $queryParams * * @return \C2iS\SocialWall\Model\SocialItemResult */ protected function retrieveItemsForLocation(array $params = array(), array $queryParams = array()) { $endpoint = '/media/search'; $content = $this->getFileContent($this->generateUrl($endpoint, $queryParams)); if (!$content) { $content = $this->getFallbackContent(); } $results = $response = $socialItems = array(); if ($content) { $response = json_decode($content); $results = $response->data; } foreach ($results as $item) { $socialItems[] = $this->createSocialItem($item); } $result = new SocialItemResult($socialItems); $result->setPreviousPage(isset($response->pagination->previous_url) ? $response->pagination->previous_url : null); $result->setNextPage(isset($response->pagination->next_url) ? $response->pagination->next_url : null); return $result; }
/** * @param object $response * * @return \C2iS\SocialWall\Model\SocialItemResult * @throws \C2iS\SocialWall\Twitter\Exception\TwitterRequestException */ protected function getItemsFromResponse($response) { if (isset($response->errors)) { $error = $response->errors[0]; throw new TwitterRequestException($error->message, $error->code); } $results = isset($response->statuses) ? $response->statuses : array(); $socialItems = array(); foreach ($results as $item) { $socialItems[] = $this->createSocialItem($item); } $result = new SocialItemResult($socialItems); $result->setPreviousPage(isset($response->search_metadata->previous_results) ? $response->search_metadata->previous_results : null); $result->setNextPage(isset($response->search_metadata->next_results) ? $response->search_metadata->next_results : null); return $result; }