YouTube API没有这样的文件或目录


YouTube API No such file or directory

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

我有谷歌api php客户端和yt示例php主目录,他说要在下载

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_one(Google_Client.php)[function.request-onex]:无法打开流:第17行/home/myusername/mysite.com/videos/yt-samples-php-master/search.php中没有这样的文件或目录

致命错误:requireonce()[function.request]:在第17行/home/myusername/mysite.com/videos/yt-samples-php-master/search.php中打开所需的"Google_Client.php"(include_path='./Google-api-php-Client/src/')失败。

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

但这似乎于事无补。如有任何线索,我们将不胜感激!

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

太晚了。但将来可能会有人在寻找这个。
解决方案:

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

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

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

是与您的项目位于同一文件夹中的google api php客户端。请确保将include设置为指向该目录。这个目录是755’ed。

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

require_once 'Google/Client.php';
require_once 'Google/Service/Youtube.php';

好吧,过一段时间我又回来了。我已经设法让search.php的例子工作通过:

  • 在search.php中,将require语句更改为:require_one’/google-api-php-client/src/google_client.php’;require_one’/google-api-php-client/src/contrib/google_YouTubeService.php;并注释掉set_include_path和后面的两行require_one

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