Created
October 31, 2015 18:44
-
-
Save ConnorMcF/b03e60d190f06ef40e21 to your computer and use it in GitHub Desktop.
Get YouTube title from ID - v3 API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function youtube_title($id) { | |
// returns a single line of JSON that contains the video title. Not a giant request. | |
$videoTitle = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=".$id."&key=YOUR_API_KEY&fields=items(id,snippet(title),statistics)&part=snippet,statistics"); | |
// despite @ suppress, it will be false if it fails | |
if ($videoTitle) { | |
$json = json_decode($videoTitle, true); | |
return $json['items'][0]['snippet']['title']; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment