PHP API客户端中的required_once问题
作者:互联网
我一直在尝试导入/包含我的PHP脚本文件中的文件,并以某种方式它无法正常工作.我知道这个require_once问题被问了很多次[1. require_once with subfolders ,2. require_once() cant find the include path,3. Using require_once for up directory not working]但是它们似乎都没有为我工作.
Blow图片将解释我想要做的事情:
我尝试了什么和错误:
尝试1
require_once(__DIR__.'GoogleClientApi/src/Google/Service/Analytics.php');
echo 'Hey1'; //Does not echo this, means something went wrong above.
require_once(__DIR__.'GoogleClientApi/src/Google/Client.php');
echo 'Hey2';
我得到的错误:
尝试2(修复了尝试1的问题但提出了另一个问题.)
所以我决定使用绝对路径:
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php';
echo 'Hey1';
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Service/Analytics.php';
echo 'Hey2';
给我Client.php文件中的错误:
`Warning: require_once(/Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php on line 18`
`Fatal error: require_once(): Failed opening required '/Google/Auth/AssertionCredentials.php' (include_path='.:/Applications/MAMP/bin/php/php5.5.10/lib/php') in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php on line 18`
Investigating upon I found Client.php (of Google APIs Client Library for PHP) has these lines which are actually present:
require_once 'Google/Auth/AssertionCredentials.php'; // <-- Can't find
require_once 'Google/Cache/File.php'; // <-- Can't find
require_once 'Google/Cache/Memcache.php'; // <-- Can't find
我不知道这里出了什么问题.修复了尝试1的问题,但现在错误发生在google自己的库中,我不知道如何克服.我想我正在做一些我无法弄清楚的傻事.任何帮助或建议将不胜感激.
解决方法:
你有没有抛弃__DIR__?通常没有/最后.所以你必须将代码更改为:
require_once(__DIR__.'/GoogleClientApi/src/Google/Service/Analytics.php');
^
我刚刚检查了你的screen shot with the error message,没有/最后.
/Applications/MAMP/htdocsGoogleClientApi/src/Google/Client.php
代替/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php
标签:google-api-php-client,require-once,php,google-analytics,include-path 来源: https://codeday.me/bug/20190830/1770149.html