Skip to content

Instantly share code, notes, and snippets.

@vidhav
Created November 6, 2015 13:50
Show Gist options
  • Save vidhav/07d47b79c9270397f87e to your computer and use it in GitHub Desktop.
Save vidhav/07d47b79c9270397f87e to your computer and use it in GitHub Desktop.
How to get videos by ids in Google API 3
<?php
$ids = array(
'spepfQLXrm4',
'OmcJbaHw2C8',
'D0-tHS7GQxM',
);
$key = '<GoogleApiKey>';
$parts = array(
'contentDetails',
'snippet',
);
$params = array(
'id' => implode(',', $ids),
'key' => $key,
'part' => implode(',', $parts),
);
$url = 'https://www.googleapis.com/youtube/v3/videos?'.http_build_query($params);
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if ($result !== false) {
$data = json_decode($result, true);
echo '<pre>'.print_r($data, true).'</pre>';
}
curl_close ($curl);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment