private function FeedsYoutubeParser::feeds_youtube_api_do_request in Feeds: YouTube Parser 7.3
Perform API request to youtube API and retreive search result.
1 call to FeedsYoutubeParser::feeds_youtube_api_do_request()
- FeedsYoutubeParser::parse in plugins/
FeedsYoutubeParser.inc - Parse the extra mapping sources provided by this parser.
File
- plugins/
FeedsYoutubeParser.inc, line 259 - Feeds parser class for YouTube.
Class
- FeedsYoutubeParser
- Class definition for YouTube Parser.
Code
private function feeds_youtube_api_do_request($url, $page_token = '', $source, $fetcher_result, $client, $youtube) {
$result = array();
$url .= "&maxResults=" . $this->config['result_per_page'];
$url .= $page_token != '' ? "&pageToken=" . $page_token : "";
$api_request_result = drupal_http_request($url);
if ($client
->getAccessToken()) {
$search_response = json_decode($api_request_result->data, TRUE);
$result['next_page_token'] = $search_response['nextPageToken'];
$video_results = array();
foreach ($search_response['items'] as $search_result) {
array_push($video_results, $search_result['id']['videoId']);
}
$video_ids = join(',', $video_results);
$part = "contentDetails,id,snippet";
if ($this->config['authenticated_on_channel']) {
$part .= ",fileDetails,player,statistics,status,topicDetails";
}
try {
$videos_response = $youtube->videos
->listVideos($part, array(
'id' => $video_ids,
));
} catch (Exception $ex) {
if (strpos($ex
->getMessage(), 'Forbidden') > -1) {
drupal_set_message(t('It seems you don\'t have access to read/view the results, please configure you feed importer !admin_link', array(
'!admin_link' => l(t('Configure'), "admin/structure/feeds/{$source->id}/settings/FeedsYoutubeParser"),
)), 'error');
}
}
if (!empty($videos_response['items'])) {
$result = $this
->parseVideoItems($videos_response, $source, $fetcher_result);
}
}
else {
throw new Exception(t('FeedsYoutubeParser: Unauthorized token.'));
}
return array(
'result' => $result,
'page_token' => $search_response['nextPageToken'],
);
}