我正在使用Composer安装Google API客户端Packagist Google API Client.
在我使用Composer安装后,需要Google/apiclient,它会像正常一样安装. 之后,我try 在下面的示例中使用它
<?php
use Google\Service\ShoppingContent;
use Google\Auth\Credentials\ServiceAccountCredentials;
/**
*
*/
class GoogleShoppingContentAPI
{
private $service;
public function __construct($credentialsPath) {
// Create the credentials object
$credentials = new ServiceAccountCredentials(
ShoppingContent::CONTENT,
$credentialsPath
);
// Create the Shopping Content Service with the credentials
$this->service = new ShoppingContent(['credentials' => $credentials]);
}
public function getProducts($merchantID)
{
try {
// Fetch a list of products
$products = $this->service->products->listProducts($merchantID);
// Return the product data as an array
return $products->getResources();
} catch (Google\Service\Exception $e) {
throw new Exception("Error: " . $e->getMessage());
}
}
}
但是,在运行代码时,它会打印出以下错误:
Class Fatal error: Uncaught Error: Class "Google\Auth\Credentials\ServiceAccountCredentials" not found in /Users/Shared/www/inc/google.inc.php on line 15
它在我们的自动加载中,在运行上面的代码之前,我们需要自动加载. Google命名空间也不会被另一个包占用.
我已经判断了我们的项目,没有发现任何与Google相关的重复名称空间. 此外,重新安装aswell Composer更新并没有改变任何事情.