Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
public function Parse()
{
require_once('Google/Client.php');
require_once('Google/Service/YouTube.php');
$client = new Google_Client();
$client->setDeveloperKey('_YOU_API_KEY_');
$youtube = new Google_Service_YouTube($client);
$search_parameters = array(
'q' => 'майнкрафт',
'maxResults' => 50,
'type' => 'video',
'videoDuration' => 'medium',
'videoEmbeddable' => 'true',
'videoSyndicated' => 'true',
'order' => 'date',
);
$c = 0;
while (1) {
try {
$search_response = $youtube->search->listSearch('id,snippet', $search_parameters);
} catch (Google_Service_Exception $e) {
$error = $e->getMessage();
throw new CHttpException(500, $error);
} catch (Google_Exception $e) {
$error = $e->getMessage();
throw new CHttpException(500, $error);
}
if (!empty($error)) {
return array('error' => $error);
}
if (isset($search_response['nextPageToken'])) {
$search_parameters['pageToken'] = $search_response['nextPageToken'];
}
$c++;
if ($c > 3) {
break;
}
foreach ($search_response['items'] as $videoResult) {
$out [] = array(
'image' => str_replace('https://', '', $videoResult['snippet']['thumbnails']['medium']['url']),
'vtitle' => $videoResult['snippet']['title'],
'video_code' => $videoResult['id']['videoId']
);
}
}
return $out;
}