roh*_*tel 3 php google-analytics require-once include-path google-api-php-client
我一直在尝试导入/包含我的PHP脚本文件中的文件,并以某种方式它无法正常工作.我知道这个require_once问题被多次询问[ 1. require_once with subfolders,2.require_once()无法找到包含路径,3.使用require_once for up directory not working ]但是它们似乎都不适用于我.
Blow图片将解释我想要做的事情:

我尝试了什么和错误:
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';
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

所以我决定使用绝对路径:
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php';
echo 'Hey1';
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Service/Analytics.php';
echo 'Hey2';
Run Code Online (Sandbox Code Playgroud)
给我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
Run Code Online (Sandbox Code Playgroud)

我不知道这里出了什么问题.修复了尝试1的问题,但现在错误发生在google自己的库中,我不知道如何克服.我想我正在做一些我无法弄清楚的傻事.任何帮助或建议将不胜感激.
你有没有抛弃过__DIR__?通常/最后都没有.所以你必须将代码更改为:
require_once(__DIR__.'/GoogleClientApi/src/Google/Service/Analytics.php');
^
Run Code Online (Sandbox Code Playgroud)
/Applications/MAMP/htdocsGoogleClientApi/src/Google/Client.php
代替 /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php