亚马逊mws-api类';MarketplaceWebService_Client';找不到错误


Amazon mws api Class 'MarketplaceWebService_Client' not found error

下载了一个解压的亚马逊MWS客户端库api后,我尝试运行其中一个脚本,看看是否一切正常。

当尝试运行文件GetReportCountSample.php时,我得到了错误

Fatal error: Class 'MarketplaceWebService_Client' not found in C:'xampp'htdocs'sites'amazon marketplace'Samples'GetReportCountSample.php on line 68

我已经查看了配置文件,并输入了我的凭据,例如:

define('AWS_ACCESS_KEY_ID', '<key id>');                 //has been input
define('AWS_SECRET_ACCESS_KEY', '<secret key id>');       //has been input
define('APPLICATION_NAME', '<Your Application Name>');   //no idea what this is
define('APPLICATION_VERSION', '<Your Application Version or Build Number>'); //no idea
define ('MERCHANT_ID', '<merch id>');                    //has been input

我找不到一个名为MarketplaceWebService_Client的php文件,我需要帮助,谢谢。

没有名为MarketplaceWebService_Client的php文件。其Client.php在您下载的库中。MarketplaceWebService_Client类仅在Client.php文件中。我认为GetReportCountSample.php中没有正确指定Client.php的include路径。Client.php可能位于以下路径中(Outside of Samples文件夹):C:''examplep''htdocs''sites''amazon marketing''Client.php

.config.inc.php内部,您将拥有以下内容:

   /************************************************************************
    * OPTIONAL ON SOME INSTALLATIONS
    *
    * Set include path to root of library, relative to Samples directory.
    * Only needed when running library from local directory.
    * If library is installed in PHP include path, this is not needed
    ***********************************************************************/
    set_include_path(get_include_path() . PATH_SEPARATOR . '../../.');

这定义了包含路径,这些路径在该程序中用于加载类的所有分类文件。每一个由CCD_ 3分隔。此函数添加了另一个include路径,该路径位于当前工作目录之上的2个目录,并且不是正确的目录。您必须指向src目录。

要解决此问题,请将'../../.'更改为指向src文件夹所在的目录。我的脚本和src目录位于同一父目录中,因此我的代码如下所示:

set_include_path(get_include_path() . PATH_SEPARATOR . getcwd().'/src/');

我意识到这是一个老问题,但我也有类似的问题,我想分享我的发现。

此处出现问题是因为您更改了库安装路径。

... not found in C:'xampp'htdocs'sites'amazon marketplace'Samples'GetReportCountSample.php

由于不包括Lib目录,它产生了这个错误。如果你通读.config.php,你会看到

function __autoload($className){
    $filePath = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
    $includePaths = explode(PATH_SEPARATOR, get_include_path());
    foreach($includePaths as $includePath){
        if(file_exists($includePath . DIRECTORY_SEPARATOR . $filePath)){
            require_once $filePath;
            return;
        }
    }
}

这意味着,一旦用下划线拆分了类,就需要正确的路径。通过这种方式,它正在寻找路径"MarketplaceWebService/client.php"。通过删除目录"MarketplaceWebService",它将无法找到该文件来定义类。

要纠正,只需将您的库安装到"htdocs''sites''amazon marketing''MarketplaceWebService''",一切都会好起来。

希望这能帮助到别人。