alaouy/YouTube

Getting localized video snippets

Closed this issue · 3 comments

Hello,

How can I fetch title and description in other language (if exists), f.ex. polish?
`$videoPolishDescription = $video->snippet->localized-> ??? ->title;

I can't write in there pl-PL, so how I can get this data?

Docs: https://developers.google.com/youtube/v3/docs/videos#snippet.localized.title

Thank you in advance ;)

@m-pastuszek You need to provide the hl param in your request query and the API will give you the localized title directly in $video->snippet->localized->title, more here https://developers.google.com/youtube/v3/docs/videos#snippet.localized

@alaouy, can You write an example? I can't get it.

@m-pastuszek Unfortunately this is not supported out of the box in this version of the package, as you can't pass extra params (hl for example to the getVideoInfo method), there is an ugly alternative to make it work like this:

$params = [
  'id'            => 'J-L-ByHzto0',
  'type'          => 'video',
  'part'          => 'id, snippet',
  'hl'            => 'de'
];

$API_URL = Youtube::getApi('videos.list');

$apiData = Youtube::api_get($API_URL, $params);
$video   = Youtube::decodeSingle($apiData);

echo $video->snippet->localized->description; // This will echo the german version of the description

Hope this helps you, and if you can create a PR to add support for extra parameters like this one that would be awesome.