I've been trying to access the "videoID" JSON object in the following array:
{
"kind": "youtube#searchListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/652q8gXfNeBDSoSQrv8VCrAv0Ho\"",
"nextPageToken": "CAUQAA",
"regionCode": "AU",
"pageInfo": {
"totalResults": 25,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/31YuvB6enDzigibEfdgUq4-ZYc0\"",
"id": {
"kind": "youtube#video",
"videoId": "Ldx1nwBd4AY"
},
"snippet": {
"publishedAt": "2017-04-14T21:00:00.000Z",
"channelId": "UC-z95jtL6-oDyFueQPoZLfQ",
"title": "HOW TO PLAY NINTENDO DS GAMES ON iPHONE iOS 10 FOR FREE (NDS4iOS) - NDS4IOS Tutorial - Tech Scout",
"description": "LIKE THE VIDEO + TURN ON CHANNEL NOTIFICATIONS! HOW TO PLAY NINTENDO DS GAMES ON iPHONE iOS 10 FOR FREE (NDS4iOS) - NDS4IOS ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Ldx1nwBd4AY/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/Ldx1nwBd4AY/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/Ldx1nwBd4AY/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Tech Scout",
"liveBroadcastContent": "none"
}
},
It continues from there but I've been trying to access the "videoID" object using the following code:
$youtubeurl = "https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=" . $channelid . "&key=" . $api;
$youtubeinfo = file_get_contents($youtubeurl);
$youtubeencoded = json_decode($youtubeinfo, true);
$youtubevideoid = $youtubeencoded["data"]["items"][0]["videoID"];
echo $youtubevideoid;
I don't have too much experience with JSON so I just got the code in the 4th line (which I think is the problem) from another question on Stack Overflow.