I'm trying to retrieve the description or just any of the data using the YouTube API and it doesn't seem to work for me >.>
What I'm doing:
<?php
$unparsed_json = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=AIzaSy...&part=snippet,contentDetails,statistics,status");
$json_object = json_decode($unparsed_json, true);
?>
<html>
<head>
<title>Music Player</title>
<link rel="stylesheet" href="/resources/app.css">
</head>
<body>
<p><?php echo $json_object['items']['description']; ?></p>
</body>
</html>
What the API outputs:
{
"kind": "youtube#videoListResponse",
"etag": "\"q5k97EMVGxODeKcDgp8gnMu79wM/HsO5dOfnOcgAuvefMmBwP_N0QX0\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"q5k97EMVGxODeKcDgp8gnMu79wM/zt9_oZje8_2zsC7FjoJEVT0leuw\"",
"id": "7lCDEYXw3mM",
"snippet": {
"publishedAt": "2012-06-20T23:12:38.000Z",
"channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
"title": "Google I/O 101: Q&A On Using Google APIs",
"description": "Antonio Fuentes speaks to us and takes questions on working with Google APIs and OAuth 2.0.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/7lCDEYXw3mM/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/7lCDEYXw3mM/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/7lCDEYXw3mM/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Google Developers",
"tags": [
"api",
"gdl",
"i-o"
],
"categoryId": "28",
"liveBroadcastContent": "none",
"localized": {
"title": "Google I/O 101: Q&A On Using Google APIs",
"description": "Antonio Fuentes speaks to us and takes questions on working with Google APIs and OAuth 2.0."
}
},
"contentDetails": {
"duration": "PT15M51S",
"dimension": "2d",
"definition": "hd",
"caption": "true",
"licensedContent": false
},
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
},
"statistics": {
"viewCount": "6785",
"likeCount": "39",
"dislikeCount": "2",
"favoriteCount": "0",
"commentCount": "11"
}
}
]
}
And the error I get is that the description is an undefined index.