通过set_include_path动态包含Google Api客户端库类


Including Google Api Client library classes through set_include_path dynamically

我想包含"google-api-php-client"的类(我手动上传到我的主机在子文件夹博客中)以在我的网站上使用,我正在尝试使用"set_include_path"功能动态包含它。但是,当应用require_once时,我的代码停在那里,所以我没有包含它们。我展示了我为此目的一直在测试的代码:

或者,您可以在代码中动态设置相同的 ini 指令。set_include_path (get_include_path () path_separator '/path/to/google-api-php-client/src'..);    

我的代码:

// 1st try with the full path to the folder classes Google Api:
set_include_path (get_include_path (). path_separator. '/home/u140888/domains/segurosq.com/public_html/blog/google-api-php-client/src'))
// 2nd try with the route from the subfolder Blog to Google Api classes:
set_include_path (get_include_path () path_separator '/ blog / google-api-php-client / src'..);
// 3rd attempt the route from the folder with Google Api classes:
set_include_path (get_include_path () path_separator '/ google-api-php-client / src'..);
// This line require_once my code stops and you can not instantiate the class within Client.php because it has not been added successfully:
require_once 'Google / Client.php';

我什至直接在include_path参数设置PHP中尝试过这个.ini进入我的cPanel托管或托管服务提供商,但没有成功。

如果你的文件在/home/u140888/domains/segurosq.com/public_html/blog/试试这个:

set_include_path ('/home/u140888/domains/segurosq.com/public_html/blog/google-api-php-client/' .PATH_SEPARATOR .get_include_path());

require_once('google-api-php-client/autoload.php');

$client = 新的 Google_Client();...

现在我很好了。问题是我没有为我的PHP 5.2版本使用正确版本的Google Api文件。现在我能够无缝地实例化这些类。感谢您的帮助,我真的很感激。:-)