首页 文章

YouTube API没有此类文件或目录

提问于
浏览
1

我是一名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/videos/中打开所需的'Google_Client.php'(include_path =' . / google-api-php-client / src /')失败第17行的yt-samples-php-master / search.php .

我注意到Google提供的文件有错字 require_once 'contrib/Google_YoutubeService.php'; 应为 require_once 'contrib/Google_YouTubeService.php';

但这似乎没有帮助 . 非常感谢任何线索!

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

4 回答

  • 0

    晚了 . 但有人可能会在将来寻找这个 .
    解:

    • Google 's php client uses composer, so, you' ve将路径放到自动加载文件中 .
      链接:Google API PHP client

    • 删除或注释 require_once()contrib/Google_YoutubeService.phprequire_once() 方法

    • 实例化时将类名从 Google_YoutubeService 重命名为 Google_Service_YouTube

  • 0

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

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

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

    同样在最新的(v1.0)php库中,他们改变了源的放置

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

    好的,我过了一会儿就回来了 . 我已经设法通过以下方式获取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的类,我重命名它,然后它工作了!

相关问题