axios 使用Youtube数据API v3时发生错误API_KEY_HTTP_REFERRER_BLOCKED

a0zr77ik  于 2022-11-05  发布在  iOS
关注(0)|答案(1)|浏览(109)

当提出请求时:

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"
        }
      }
    ]
  }
}
5gfr0r5j

5gfr0r5j1#

出现错误是因为请求的http引用违反了API密钥HTTP限制。
请检查项目的API_KEY设置。
您可以在the documentation feature中尝试该请求并查看结果:
网址: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"
      }
    }
  ]
}

相关问题