YouTube API v3 retrieves latest video uploads for username using PHP

I am trying to get a list of users of the latest videos / downloads. I’m trying to figure out this new v3 API, but I can’t find suitable working examples of PHP code, even on the dedicated YouTube API website.

I have a list of YouTube usernames and I just want to just get a list of my latest videos with a video id, title, thumbnail, etc. Mostly in the foreach loop.

Any tips?

I have the following code, I need to get it to work with the actual YouTube usernames.

$url = 'https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=ferrariworld&key=ZZZZZZZZ';
$json = json_decode(file_get_contents($url), true);
foreach ($json as $item){
echo $item[0]['id'];
echo $item[0]['title'];
}
+4
source share
1 answer

forUsername (. ).

GET https://www.googleapis.com/youtube/v3/channels?part=id&forUsername={USERNAME}&key={YOUR_API_KEY}

:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/7Q8DJLb6b2hwYAXUQLI3ftt3R8U\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {

   "kind": "youtube#channel",
   "etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/pDjr9xPn51KtRM3gbMOq2aHBIbY\"",
   "id": "UCr3LuetcEeidWiuhxaw4B2g"
  }
 ]
}

items[0]['id'], JSON .

, JSON. - .

if (array_key_exists('items', $json) && count($json['items']) === 1) {
    $item = $json['items'][0];

    $channelId = $item['id']; // The users channel ID.
}
+2

All Articles