【问题标题】:YouTube API No such file or directoryYouTube API 没有这样的文件或目录
【发布时间】:2013-12-05 16:45:44
【问题描述】:

我是一名 PHP 新手,在 http://www.youtube.com/watch?v=LMhN6pCAZWo 试用 YouTube API 演示。

我有他说要下载的 google-api-php-client 和 yt-samples-php-master 目录

www.mysite.com/video/google-api-php-client 和 www.mysite.com/video/yt-samples-php-master

search.php 文件位于 yt-samples-php-master 中,我已复制视频并设置:

if ($_GET['q'] && $_GET['maxResults']) {
set_include_path("./google-api-php-client/src");
// Call set_include_path() as needed to point to your client library.
require_once 'Google_Client.php';
require_once 'contrib/Google_YouTubeService.php';

我可以很好地访问 www.mysite.com/videos/yt-samples-php-master/search.php 但是当我搜索时我收到消息:

警告:require_once(Google_Client.php) [function.require-once]:无法打开流:/home/myusername/mysite.com/videos/yt-samples-php-master/search 中没有这样的文件或目录.php 在第 17 行

致命错误:require_once() [function.require]:无法在 /home/myusername/mysite.com 中打开所需的 'Google_Client.php' (include_path='./google-api-php-client/src/') /videos/yt-samples-php-master/search.php 在第 17 行。

我注意到 Google 提供的文件有一个拼写错误 require_once 'contrib/Google_YoutubeService.php'; 应该是require_once 'contrib/Google_YouTubeService.php';

但这似乎没有帮助。任何线索将不胜感激!

编辑:我还通过视频目录将 755 递归设置为子目录和文件

【问题讨论】:

  • 您想从该视频中获取详细信息还是获取所有视频?
  • 嗨。首先,我只想使用 search.php 上的搜索并返回视频。一旦我得到正确的包含位置,我肯定想尝试学习其他选项

标签: php youtube youtube-api


【解决方案1】:

只需替换此./ 并尝试以下格式

set_include_path("google-api-php-client/src");

【讨论】:

  • 谢谢。我已经尝试过了,错误只是更改为:Warning: require_once(Google_Client.php) [function.require-once]: failed to open stream: No such file or directory in /home/username/mysite.com/videos/yt-samples-php-master/search.php on line 18 Fatal error: require_once() [function.require]: Failed opening required 'Google_Client.php' (include_path='google-api-php-client/src') in /home/username/mysite.com/videos/yt-samples-php-master/search.php on line 18
  • @Stuart Brown 我也有同样的问题。如果你解决了吗?请帮助我...谢谢。
  • 我在上面给出的答案(1 月 6 日 21:23)对我有用。
  • 我解决了不同的方法。在我创建开发人员控制台“服务器密钥”之前,当我重新创建密钥“浏览器密钥”时。这次为我工作。谢谢
【解决方案2】:

google-api-php-client 是否与您的项目位于同一文件夹中。确保将包含设置为指向该目录。那个目录是 755'ed。

在最新的 (v1.0) php 库中,他们将源代码的位置更改为

require_once 'Google/Client.php';

require_once 'Google/Service/Youtube.php';

【讨论】:

    【解决方案3】:

    好的,过了一会儿我又回来了。我已经设法让 search.php 示例工作:

    • 在 search.php 中将 require 语句更改为: require_once './google-api-php-client/src/Google_Client.php'; require_once './google-api-php-client/src/contrib/Google_YouTubeService.php'; 并注释掉 set_include_path 并遵循两条 require_once 行。

    这会导致一个致命错误,即在 Google_YouTubeService.php 中找不到类 Google_Service_YouTube。然而,在该文件中有一个名为 Google_YouTube_Service 的类,我对其进行了重命名,然后它就起作用了!

    【讨论】:

      【解决方案4】:

      时间不早了。但将来有人可能会寻找这个。
      解决方案:

      • Google 的 php 客户端使用 composer,因此,您必须将路径放入自动加载文件。
        链接:Google API PHP client
      • 删除或注释掉 Google_Client.phpcontrib/Google_YoutubeService.phprequire_once() 方法
      • 在实例化时将类名从 Google_YoutubeService 重命名为 Google_Service_YouTube

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-25
        • 2021-06-24
        • 2015-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-17
        相关资源
        最近更新 更多