我有下面的代码。当我运行它时,我得到错误:
Fatal error: Cannot redeclare class Google_Account in
/var/www/vhosts/example.com/httpdocs/google-api-php-client
/src/contrib/Google_AnalyticsService.php on line 379
这是因为“ Google_AdsenseService.php ”和“ Google_AnalyticsService.php ”文件都有一个名为Google_Account
. Google_Account 类的成员变量和函数在这些文件中是不同的。
我需要同时获取 Adsense 和 Analytics 数据。所以我需要同时使用这两种服务。我找不到取消声明类的方法。如何同时使用这两项服务?
include_once APP.'Vendor/google-api-php-client/src/Google_Client.php';
$client1 = new Google_Client();
$client1->setApplicationName('aaa');
$client1->setDeveloperKey('1234');
$client1->setRedirectUri('http://example.com/');
include_once APP.'Vendor/google-api-php-client/src/contrib/Google_AdsenseService.php';
$client1->setClientId('2345');
$client1->setClientSecret('4444');
$service1 = new Google_AdsenseService($client1);
// some code that gets data from "$service1"
$client2 = new Google_Client();
$client2->setApplicationName('aaa');
$client2->setDeveloperKey('1234');
$client2->setRedirectUri('http://example.com/');
include_once APP.'Vendor/google-api-php-client/src/contrib/Google_AnalyticsService.php';
$client2->setClientId('4567');
$client2->setClientSecret('5555');
$service2 = new Google_AnalyticsService($client2);
// some code that gets data from "$service2"