Benjamin-Loison / YouTube-operational-API

YouTube operational API works when YouTube Data API v3 fails.
401 stars 52 forks source link

*The provided API key has an IP address restriction. The originating IP address of the call (INSTANCE_IPV6) violates this restriction.* on private instance no-key service #306

Closed Benjamin-Loison closed 2 months ago

Benjamin-Loison commented 2 months ago
<?php

include_once 'common.php';

$message = 'The provided API key has an IP address restriction. The originating IP address of the call (2603:c027:c002:b800:dfc1:efbf:49e:f15a) violates this restriction.';
//echo preg_quote($message);
echo checkRegex('The provided API key has an IP address restriction\. The originating IP address of the call \([0-9a-f:]{38}\) violates this restriction\.', $message) ? 'true' : 'false';

works but not:

echo checkRegex('The provided API key has an IP address restriction\. The originating IP address of the call \([0-9a-f:]{,39}\) violates this restriction\.', $message) ? 'true' : 'false';

https://www.php.net/manual/en/regexp.reference.repetition.php

Wikipedia: IPv6#Address representation (1245019371)

A shortest IPv6 seems to be: 0::0.

Benjamin-Loison commented 2 months ago
echo checkRegex('The provided API key has an IP address restriction\. The originating IP address of the call \([0-9a-f:]{4,39}\) violates this restriction\.', $message) ? 'true' : 'false';

Source: the Stack Overflow answer 3261606

works fine.

https://www.php.net/manual/en/function.preg-quote.php

https://www.php.net/manual/en/function.preg-match.php

Benjamin-Loison commented 2 months ago

Still have the issue for an IPv4 instance.

Benjamin-Loison commented 2 months ago
<?php

function checkRegex($regex, $str)
{
    return preg_match("/^$regex$/", $str) === 1;
}

$message = '92';
echo "$message\n";
$regex = '\d{2}';
echo "$regex\n";
echo checkRegex($regex, $message) ? 'true' : 'false';
echo "\n";