YouTube API No such file or directory - php

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

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

Just replace this ./ and try this following format
set_include_path("google-api-php-client/src");

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

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!

Related

wrong path using 'require'

Since moving my website from local to online , I have a path problem using require.
I have pages that call bootstrap.php like this:
require 'inc/bootstrap.php';
And boostrap.php looks like this:
<?php
spl_autoload_register('app_autoload');
function app_autoload($class){
require "class/$class.php";
}
This worked well in local.
Now, online, I get the following message:
Warning: require_once(/home/website/www/class/functions.php): failed to open stream: No such file or directory in /home/website/www/inc/bootstrap.php on line 6
Fatal error: require_once(): Failed opening required '/home/website/www/class/functions.php' (include_path='.:/usr/share/php:/usr/share/pear')
in /home/website/www/class/functions.php on line 6
So I thought, I should put an absolute path in boostrap.php like this:
<?php
spl_autoload_register('app_autoload');
function app_autoload($class){
$path = $_SERVER['DOCUMENT_ROOT'] . "class/$class.php";
require_once "$path";
}
But I get the exact same error.
I dont understand why it is still looking in the /home/website/www/inc/bootstrap.php and not following the absolute path which is /home/website/www/class/functions.php ?
EDIT:
After testing the different solutions using absolute pathes, I am still getting the error that "No such file or directory in /home/website/www/bootstrap.php: so it is still looking in the file instead of directory.
Could it be because I am using a double require? I first require boostrap.php from description.php (which works fine) and then I require class.php from this boostrap.php (which doesent take the absolute path but the path corresponding to the file boostrap.php ?
ANSWER:
Ok it finally works with this configuration:
First file using require:
require_once(dirname(__FILE__). '/inc/bootstrap.php');
and boostrap.php:
require_once(dirname(__FILE__). "/../class/$class.php");
As it was said in comments, it is safe to use absolute path instead of 'inc/...', cause it is relative to current class execution path, i.e.:
define ('BASE_PATH', dirname(__FILE__).'/../');
Then use BASE_PATH.{your_path} to access files.
I suggest to use require_once to avoid multiple inclusions.

Implementing Oauth2 login, Fatal error: Class 'Google_Service' not found

I am updating my website's login system from LightOpenID to Google's Oauth 2.0.
When I require the Client.php and the Service/Oauth2.php I get an error
Fatal error: Class 'Google_Service' not found in /home/myname/repos/website_current/lib/google-api-php-client/src/Google/Service/Oauth2.php on line 32
The code I am using (from my login.php file) looks like this
require_once(dirname($_SERVER['DOCUMENT_ROOT']).'/lib/autoload.php');
require('Google/Client.php');
require('Google/Service/Oauth2.php');
echo "exit";
exit();
I have added the include path in the PHP.ini (in /etc/php5/apache2/php.ini) as
include_path = ".:/usr/local/lib/php:/home/myname/repos/website_current/lib/google-api-php-client/src"
So its seems my Oauth2.php file can't see any of the other includes including the class 'Google_Service' which is one folder up in 'Service.php'.
My folder structure looks like this:
lib/
... autoload.php
... functions.php
... google-api-php-client/
... src/
... Google/ (etc etc)
public_html/
... login/
...login.php
I have no idea why this is occuring. The include path should be seen, and shows up as an included path using phpinfo(); Can someone please give me some insight?
Make sure you add the line BEFORE any other Google "require_once" lines.
require_once 'google-api-php-client/autoload.php';
I had it last and it had me scratching my head for a good 10 minutes.
Per the instruction on github:
require_once 'google-api-php-client/autoload.php'; // or wherever autoload.php is located
In your case it seems like the above include url should work fine.
The new way of doing this (circa early 2016) is
require_once("Google/autoload.php");
(Assuming you have already set your include path to have /path/to/google-api-php-client/src)
As of Nov 2016
require_once ... 'vendor/autoload.php';
To this version https://github.com/google/google-api-php-client this is a posible solution
set_include_path("google-api-php-client/src/" . PATH_SEPARATOR . get_include_path());
//.....
require_once 'Google/Service.php';
//.....
While working with Google API integration
Fatal error: Class 'abc' not found
error comes when there is definitely something different between the library you have in composer.json above, and the library that is actually being auto-loaded.
had same problem just changed in my composer.json
{"require": {"google/apiclient": "1.0.*#beta"}}
to
{"require": {"google/apiclient": "2.0.*"}}
and then execute php composer.phar update (make sure you give right path for .phar file)
Now it is deprecated and moved to Sub Google directory. Following is the new default path:
google-api-php-client-master\src\Google\autoload.php
After following what Durandal had posted I tried it, but the new path for me is :
require_once 'google-api-php-client/src/Google/autoload.php';
Once I made this changed it worked. Thanks for the help.

Multiple require_once and active folders

I'm trying to implement Google APIs in PHP on WAMP, but I can't even manage to include the files.
My code is the following :
<?php
require_once "./vendor/google/apiclient/src/Google/Client.php";
Client.php
require_once 'Google/Auth/AssertionCredentials.php';
require_once 'Google/Cache/File.php';
require_once 'Google/Cache/Memcache.php';
....
My error :
Warning: require_once(Google/Auth/AssertionCredentials.php): failed to
open stream: No such file or directory in
C:\wamp\www\mysite\vendor\google\apiclient\src\Google\Client.php on
line 18
How should I use include path, and similar commands to get Client.php to find what it wants ?
There are multiple ways so that the file can be found. These include the absolute path or also using setting the include path. The include path can be set via:
php.ini
.htaccess
ini_set function
set_include_path function
Please goole the one most appropriate for your use
I solved my problem using Composer.

Using PEAR XMLRPC2 inside wordpress plugin

I am trying to run the PEAR XMLRPC inside a plugin function to do some validation. It is all working fine in a standalone app that in a folder on my server, but as soon as I put all the files into my plugin folder, the:
require_once 'XML/RPC2/Client.php';
doesn't work. The Client.php file return an error:
Warning: require_once(XML/RPC2/Exception.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream:
So i assume it has to do with relative vs non-relative files, but I can't seem to figure out why it works outside of wordpress just fine.
If I start changing all the
require_once 'XML/RPC2...
to be the absolute path on the server the errors start going away, but I feel like I shouldn't have to change the source of PEAR and XMLRPC to do what i need. Any Suggestions?
You could update the PHP include path:
set_include_path(get_include_path() . PATH_SEPARATOR . $pathToPearLibs);
require_once($pathToPearLibs . 'XML/RPC2/Client.php');
This will give PHP one more (correct) place to look after it attempts to load from the wrong place.

Zend Gdata include path issue (Loader.php)

I've been trying to install Zend Gdata. I'm running from a dev environment so have access to php.ini.
I've set the include path and when I run the verification script I get the following..
Ran PHP Installation Checker on 2011-04-28T02:25:20+00:00
PHP Extension Errors Tested
No errors found
Zend Framework Installation Errors Tested
No errors found
SSL Capabilities Errors Tested
No errors found
YouTube API Connectivity Errors Tested
No errors found
But when I try to run any of the demo files I get the floowing error...
Warning: require_once(Zend/Loader.php): failed to open stream: No such file or directory in /usr/lib/php/ZendGdata/demos/Zend/Gdata/blogger.php on line 37
Fatal error: require_once(): Failed opening required 'Zend/Loader.php' (include_path='.:/usr/lib/php') in /usr/lib/php/ZendGdata/demos/Zend/Gdata/blogger.php on line 37
The most logical conclusion is that there is a problem with the include path, but I have checked it and it seems right.
Here's what I have for it...
.:/usr/lib/php/ZendGdata/library/Zend:/usr/lib/php/ZendGdata/library/
Any suggestions would be greatly appreciated.
Put this in the beginning of Blogger.php
set_include_path('/usr/lib/php/ZendGdata/library' . PATH_SEPARATOR . get_include_path());
You say you're setting the include path in a configuration file but that doesn't seem to be affecting CLI. Make sure you're editing the right php.ini file with php --ini
$clientLibraryPath = 'ZendGdata/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
if you do not know the root path of the server, use relative path for accessing library. Its pretty handy to use.
above two lines should be written on the top of any file{page1,page2,page3} having folder structure as below
Website
Page1.php
Page2.php
Page3.php
ZendGdata
You can use your relative path as per your need

Categories