Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error API_KEY_HTTP_REFERRER_BLOCKED ocurred at using Youtube Data API v3

When making a request to:

https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=5&key=<MY_API_KEY>&q=dogs

I get the following error response:

  "error": {
    "code": 403,
    "message": "Requests from referer \u003cempty\u003e are blocked.",
    "errors": [
      {
        "message": "Requests from referer \u003cempty\u003e are blocked.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "API_KEY_HTTP_REFERRER_BLOCKED",
        "domain": "googleapis.com",
        "metadata": {
          "consumer": "projects/119952101582",
          "service": "youtube.googleapis.com"
        }
      }
    ]
  }
}
like image 991
Tawsif Haque Avatar asked Aug 31 '25 18:08

Tawsif Haque


1 Answers

I just had the same issue. In my case I had to explicitly set the referer cURL option. I was using PHP + cURL, but there is probably an equivalent for your setup. I was scratching my head that it was empty as well and not derived by Google when it received the request. So for me I added this to my cURL request: curl_setopt($curl, CURLOPT_REFERER, "https://www.myexamplewebsite.com/");

So in the Google API restriction console, you would have something like this: https://www.myexamplewebsite.com/*

Hope this helps in your scenario.

like image 62
johnsnails Avatar answered Sep 02 '25 21:09

johnsnails