YouTube 在使用 file_get_contents 时给我错误提示
YouTube giving me error while using file_get_contents
所以我正在尝试将 YouTube 代码从 API v2 更新到 v3,但是 file_get_contents() 一直给我一个错误。
这是我的代码:
stream_context_set_default(['http' => ['ignore_errors' => true]]);
$url = file_get_contents('https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId=PLwC9H0qrxrLyQsNFq37MeivYOMOBxfCdo&key=MY_API_KEY');
echo $url;
这是我被抛出的错误信息
stdClass Object
(
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => usageLimits
[reason] => accessNotConfigured
[message] => Access Not Configured. The API (YouTube Data API) is not enabled for your project. Please use the Google Developers Console to update your configuration.
[extendedHelp] => https://console.developers.google.com
)
)
[code] => 403
[message] => Access Not Configured. The API (YouTube Data API) is not enabled for your project. Please use the Google Developers Console to update your configuration.
)
)
我建立了一个新的 API 项目,甚至刷新了我的密钥。我真的不知道我做错了什么。
确保您已为您的项目启用 YouTube 数据 API。
进入开发者控制台,select 你的项目,然后 select 'APIs & auth' 然后 APIs。您将获得一个包含热门 API 列表的页面。 Select YouTube 数据 API 并点击 'Enable API'。
您需要在 developers console 中启用 YouTube 数据 API。您可以通过单击您的项目并转到 APIs & auth > APIs 来完成此操作。在那里,您搜索 YouTube 数据 API 并通过单击启用 API 来启用它。
您现在应该可以通过您的项目访问 YouTube 数据 API 端点。
所以我正在尝试将 YouTube 代码从 API v2 更新到 v3,但是 file_get_contents() 一直给我一个错误。
这是我的代码:
stream_context_set_default(['http' => ['ignore_errors' => true]]);
$url = file_get_contents('https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId=PLwC9H0qrxrLyQsNFq37MeivYOMOBxfCdo&key=MY_API_KEY');
echo $url;
这是我被抛出的错误信息
stdClass Object
(
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => usageLimits
[reason] => accessNotConfigured
[message] => Access Not Configured. The API (YouTube Data API) is not enabled for your project. Please use the Google Developers Console to update your configuration.
[extendedHelp] => https://console.developers.google.com
)
)
[code] => 403
[message] => Access Not Configured. The API (YouTube Data API) is not enabled for your project. Please use the Google Developers Console to update your configuration.
)
)
我建立了一个新的 API 项目,甚至刷新了我的密钥。我真的不知道我做错了什么。
确保您已为您的项目启用 YouTube 数据 API。
进入开发者控制台,select 你的项目,然后 select 'APIs & auth' 然后 APIs。您将获得一个包含热门 API 列表的页面。 Select YouTube 数据 API 并点击 'Enable API'。
您需要在 developers console 中启用 YouTube 数据 API。您可以通过单击您的项目并转到 APIs & auth > APIs 来完成此操作。在那里,您搜索 YouTube 数据 API 并通过单击启用 API 来启用它。
您现在应该可以通过您的项目访问 YouTube 数据 API 端点。