Youtube api blocks cloudflare (?)

The YouTube API is blocking Cloudflare. I tested it from different hosts not connected to Cloudflare, and it only blocks hosts using Cloudflare.

Example:

<?php
$videojsonurl='https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/watch?v=1D3t_S-1AcU';
$videojson = file_get_contents("$videojsonurl");
$jvideos = json_decode($videojson);
$vchannelurl= $jvideos->author_url;
if ($vchannelurl == "") {
echo "warning"; }
else echo "$vchannelurl";
?>

It works on different hosts but doesn’t work on Cloudflare only.

The response I receive:
[25-Oct-2023 09:13:25 UTC] PHP Warning: file_get_contents(https://www.youtube.com/oembed?format=json&amp;url=https://www.youtube.com/watch?v=1D3t_S-1AcU): Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
in /home/test1.php on line 3
[25-Oct-2023 09:13:25 UTC] PHP Warning: Attempt to read property “author_url” on null in /home/test1.php on line 5

Are you aware of this situation, and do you have a solution?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.