1

I’ve a simple PHP component that fetches videos from a public playlist on YouTube. I’m using Google’s official PHP SDK and authenticated with a server key (as I only need to access public data, not data in a user context).

Throughout development and into staging, this component has worked fine. However, I’ve moved the application to the client’s production server (a GoDaddy hosting account) and the component’s suddenly stopped working, instead throwing the following error:

Google_Service_Exception in REST.php line 83: Error calling GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLAYLIST_ID&userIp=SERVER_IP&key=DEVELOPER_KEY: (403) There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.

I don’t understand. The server’s IP address is white-listed in the Google API Console. I know it’s the correct IP address, as I’ve sent a HTTP POST request from the server to another PHP script and captured the REMOTE_ADDR server variable.

I’ve also tried specifying the IP address in the request itself. The full code:

$client = new Google_Client;
$client->setApplicationName($appName);
$client->setDeveloperKey($developerKey);

$service = new Google_Service_YouTube($client);

$service->playlistItems->listPlaylistItems('snippet', array(
    'maxResults' => 50,
    'playlistId' => $collectionId,
    'userIp' => $serverIp,
));

So what’s going? Why is Google deciding it’s not playing ball with the production server?

Martin Bean
  • 38,379
  • 25
  • 128
  • 201
  • I have a WordPress plugin for which I require users to create their own server key and enter it in the settings-page. After having had a lot of users reporting IP restrictions-errors, I decided to tell them not to fill out an IP to restrict access any more (as here as well it's just for simple read-calls of public data). So when push comes to shove, you may have to consider that too? – futtta Apr 15 '15 at 12:12
  • @futtta I’ve removed the IP addresses from the Console and it now says “Any IP address permitted”, but I’m still getting the error when viewing the web page. Could it be that GoDaddy’s servers are black-listed by Google? – Martin Bean Apr 15 '15 at 12:54
  • I've seen that as well, seems like there's caching going on at Google's. Normally everything should work fine if you give it some time. – futtta Apr 15 '15 at 14:00

0 Answers0