【发布时间】:2014-08-09 05:13:42
【问题描述】:
我一直在尝试在我的 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 自己的库中,我不知道如何克服。我假设我正在做一些我无法弄清楚的愚蠢的事情。任何帮助或建议将不胜感激。
【问题讨论】:
-
复制 Google 目录和所有子目录将它放在与您尝试运行的 PHP 文件相同的目录中。这可能会有所帮助daimto.com/google-oauth2-php
-
我会检查并发表评论。感谢您的建议。
-
@DaImTo :库文件似乎存在问题。
Warning: require_once(Google/Auth/OAuth2.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Auth/AssertionCredentials.php on line 18。那么 OAuth2.php 和 AssertionCredentials.php 位于 Auth 下的同一目录中,它尝试使用 AssertionCredentials.php 中的require_once "Google/Auth/OAuth2.php";查看错误目录
标签: php google-analytics include-path google-api-php-client require-once