使用 Youtube Data API v3 时发生错误 API_KEY_HTTP_REFERRER_BLOCKED

问题描述 投票:0回答:3

提出请求时:

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

我收到以下错误响应:

  "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"
        }
      }
    ]
  }
}
axios youtube-api youtube-data-api google-apis-explorer
3个回答
0
投票

该错误是因为请求的http引用地址违反了API密钥HTTP限制。

检查您项目的 API_KEY 设置。

您可以在文档功能中尝试该请求并查看结果:

网址:

https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=5&type=video&key=[YOUR_API_KEY]

结果:

{
  "kind": "youtube#searchListResponse",
  "etag": "4Jd7oMmX6dodoqxeiB24wLkVMPY",
  "nextPageToken": "CAUQAA",
  "regionCode": "CO",
  "pageInfo": {
    "totalResults": 1000000,
    "resultsPerPage": 5
  },
  "items": [
    {
      "kind": "youtube#searchResult",
      "etag": "ZQVJo2CIwtFFTHVA4hq4gLBld_w",
      "id": {
        "kind": "youtube#video",
        "videoId": "Ci3TMqWfNLs"
      },
      "snippet": {
        "publishedAt": "2020-09-17T22:08:22Z",
        "channelId": "UCKTWUJqT3NSZ50I49ExjWZQ",
        "title": "Master KG - Jerusalema feat. Micro TDH &amp; Greeicy &amp; Nomcebo Zikode – [Remix] (Official Video)",
        "description": "Master KG - Jerusalema feat. Micro TDH & Greeicy & Nomcebo Zikode – [Remix] (Official Video) SUBSCRIBETE ▷ https://war.lnk.to/subscribe Ya disponible en ...",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/Ci3TMqWfNLs/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/Ci3TMqWfNLs/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/Ci3TMqWfNLs/hqdefault.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Warner Música",
        "liveBroadcastContent": "none",
        "publishTime": "2020-09-17T22:08:22Z"
      }
    },
    {
      "kind": "youtube#searchResult",
      "etag": "vgvtwWrC2W3mxKzGxE2tL8K5xC4",
      "id": {
        "kind": "youtube#video",
        "videoId": "dZauWAlZwl4"
      },
      "snippet": {
        "publishedAt": "2020-12-04T00:00:08Z",
        "channelId": "UCEFNzT2RoVqGkV4e3Osyx4A",
        "title": "Piso 21 &amp; Maluma - Más De La Una (Video Oficial)",
        "description": "Piso 21 & Maluma - Más De La Una (Video Oficial) Suscríbete ahora al canal oficial de Piso 21: http://bit(.)ly/Piso21 Escucha todos los éxitos de Piso 21 aquí: ...",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/dZauWAlZwl4/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/dZauWAlZwl4/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/dZauWAlZwl4/hqdefault.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Piso 21",
        "liveBroadcastContent": "none",
        "publishTime": "2020-12-04T00:00:08Z"
      }
    },
    {
      "kind": "youtube#searchResult",
      "etag": "KUGKha-wikLcojZUG_IFiIDfqns",
      "id": {
        "kind": "youtube#video",
        "videoId": "zLX_GcXt2pI"
      },
      "snippet": {
        "publishedAt": "2015-10-15T05:00:01Z",
        "channelId": "UC5imdbLT1yRvjbyqeHhnt0A",
        "title": "Manuel Medrano - Bajo El Agua (Video Oficial)",
        "description": "Descarga en iTunes: https://itunes.apple.com/co/album/bajo-el-agua-single/id1015028641 Adquiere en Google Play: ...",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/zLX_GcXt2pI/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/zLX_GcXt2pI/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/zLX_GcXt2pI/hqdefault.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Manuel Medrano",
        "liveBroadcastContent": "none",
        "publishTime": "2015-10-15T05:00:01Z"
      }
    },
    {
      "kind": "youtube#searchResult",
      "etag": "w6n0QzKBHByHu-HNiG8Lh3SkNUA",
      "id": {
        "kind": "youtube#video",
        "videoId": "0EqHqPvXcMU"
      },
      "snippet": {
        "publishedAt": "2019-09-06T05:00:04Z",
        "channelId": "UCEFNzT2RoVqGkV4e3Osyx4A",
        "title": "Piso 21 &amp; Christian Nodal - Pa&#39; Olvidarme De Ella (Video Oficial)",
        "description": "No olvides suscribirte al canal de Piso 21 para ver los últimos videos musicales oficiales, audio oficial, álbumes y más! Sigue a Piso 21 en: Facebook: ...",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/0EqHqPvXcMU/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/0EqHqPvXcMU/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/0EqHqPvXcMU/hqdefault.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Piso 21",
        "liveBroadcastContent": "none",
        "publishTime": "2019-09-06T05:00:04Z"
      }
    },
    {
      "kind": "youtube#searchResult",
      "etag": "wHEXK_WA_JcIMFQ89iipYVAxp7U",
      "id": {
        "kind": "youtube#video",
        "videoId": "W4dioKwTm1A"
      },
      "snippet": {
        "publishedAt": "2021-10-15T00:00:12Z",
        "channelId": "UClZuKq2m0Qu-HkopkSBLpEw",
        "title": "Lalo Ebratt, Maluma - Sukutubla (Official Video)",
        "description": "Lalo Ebratt, Maluma - Sukutubla (Official Video) Top Hits: https://smarturl.it/malumatophits My Channel: https://smarturl.it/ytmaluma Maluma: ...",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/W4dioKwTm1A/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/W4dioKwTm1A/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/W4dioKwTm1A/hqdefault.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Maluma",
        "liveBroadcastContent": "none",
        "publishTime": "2021-10-15T00:00:12Z"
      }
    }
  ]
}

0
投票

我刚刚遇到了同样的问题。就我而言,我必须显式设置引用 cURL 选项。我使用的是 PHP + cURL,但可能有一个适合您的设置。我百思不得其解,当谷歌收到请求时,它也是空的,而且不是由谷歌衍生的。所以对我来说,我将其添加到我的 cURL 请求中:

curl_setopt($curl, CURLOPT_REFERER, "https://www.myexamplewebsite.com/");

因此,在 Google API 限制控制台中,您将看到如下内容:

https://www.myexamplewebsite.com/*

希望这对您的情况有所帮助。


-1
投票

我在这里找到了解决方案:

https://answebtechnologies.in/blog/API_KEY_HTTP_REFERRER_BLOCKED/

访问:https://console.developers.google.com/apis

导航到 Cloud Console 中的 API 和服务 > 凭据面板。

选择现有 API 密钥的名称。

关闭限制(见截图)

© www.soinside.com 2019 - 2024. All rights reserved.