Stuart Brown
Stuart Brown

Reputation: 987

YouTube API No such file or directory

I'm a PHP newb trying out the YouTube API demo at http://www.youtube.com/watch?v=LMhN6pCAZWo.

I have the google-api-php-client and yt-samples-php-master directories that he says to download at

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

the search.php file is in yt-samples-php-master and I have replicated the video and set:

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';

I can get to www.mysite.com/videos/yt-samples-php-master/search.php fine but when I search I get message:

Warning: require_once(Google_Client.php) [function.require-once]: failed to open stream: No such file or directory in /home/myusername/mysite.com/videos/yt-samples-php-master/search.php on line 17

Fatal error: require_once() [function.require]: Failed opening required 'Google_Client.php' (include_path='./google-api-php-client/src/') in /home/myusername/mysite.com/videos/yt-samples-php-master/search.php on line 17.

I noticed that the files Google make available have a typo require_once 'contrib/Google_YoutubeService.php'; should be require_once 'contrib/Google_YouTubeService.php';

but that doesn't seem to help. Any clues would be very gratefully received!

EDIT: I've also set 755 recursively through videos directory to sub-directories and files

Upvotes: 1

Views: 4834

Answers (4)

ssi-anik
ssi-anik

Reputation: 3694

It's late. but someone may be looking for this in future.
Solution:

  • Google's php client uses composer, so, you've to put the path to the autoload file.
    Link: Google API PHP client
  • Remove or comment out require_once() methods for Google_Client.php & contrib/Google_YoutubeService.php
  • Rename class name from Google_YoutubeService to Google_Service_YouTube while instantiating

Upvotes: 3

Stuart Brown
Stuart Brown

Reputation: 987

OK I've come back to this after a little while. I've managed to get the search.php example to work by:

  • In search.php changing the require statements to: require_once './google-api-php-client/src/Google_Client.php'; require_once './google-api-php-client/src/contrib/Google_YouTubeService.php'; and commenting out the set_include_path and following two require_once lines.

This lead to a fatal error saying that class Google_Service_YouTube could not be found in Google_YouTubeService.php. In that file there was however a class called Google_YouTube_Service which I renamed and then it worked!

Upvotes: 0

Ibrahim Ulukaya
Ibrahim Ulukaya

Reputation: 12877

Is google-api-php-client in the same folder as your project. Make sure you are setting the include to point to that directory. And that directory is 755'ed.

Also in latest (v1.0) php library they changed placing of sources to

require_once 'Google/Client.php';

require_once 'Google/Service/Youtube.php';

Upvotes: 0

Padmanathan J
Padmanathan J

Reputation: 4620

Just replace this ./ and try this following format

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

Upvotes: 0

Related Questions