【问题标题】:YouTube giving me error while using file_get_contentsYouTube 在使用 file_get_contents 时给了我错误
【发布时间】:2015-09-02 08:21:40
【问题描述】:

所以我正在尝试将 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 项目,甚至刷新了我的密钥。老实说,我不知道我做错了什么。

【问题讨论】:

    标签: json youtube youtube-api


    【解决方案1】:

    您需要在developers console 中启用 YouTube 数据 API。您可以通过单击您的项目并转到 APIs & auth > APIs 来做到这一点。在那里,您搜索 YouTube Data API 并通过单击启用 API 来启用它。

    您现在应该可以通过您的项目访问 YouTube 数据 API 端点了。

    【讨论】:

    • 天哪,我觉得自己像个彻头彻尾的白痴。。成功了,非常感谢。由于您首先回答了我的问题,因此我将您的问题标记为解决方案。
    【解决方案2】:

    确保您为您的项目启用了 YouTube 数据 API。

    进入开发者控制台,选择您的项目,然后选择“APIs & auth”,然后选择 APIs。您将获得一个包含流行 API 列表的页面。选择 YouTube 数据 API,然后点击“启用 API”。

    【讨论】:

    • 天哪,我觉得自己像个白痴。。成功了,非常感谢。由于您首先回答了我的问题,因此我没有将您的问题标记为解决方案,但是您肯定应该获得一些积分! :D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多