我尝试配置Google Ad-words API但是当我执行代码时,会出现以下错误:
致命错误:未捕获错误:类 '谷歌\ ADSAPI \ COMMON \ OAuth2TokenBuilder'找不到 /var/www/html/contabilidade/post-manager/wp-content/themes/monitor/functions/backend/access.php 在第368行(!)错误:类 '谷歌\ ADSAPI \ COMMON \ OAuth2TokenBuilder'找不到 /var/www/html/contabilidade/post-manager/wp-content/themes/monitor/functions/backend/access.php 在第368行
这是获取值的代码:
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSession;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201708\cm\CampaignService;
use Google\AdsApi\Common\OAuth2TokenBuilder;
class GetCampaignsWithAwql {
const PAGE_LIMIT = 500;
public static function runExample(AdWordsServices $adWordsServices,
AdWordsSession $session) {
$campaignService = $adWordsServices->get($session, CampaignService::class);
// Create AWQL query.
$query = 'SELECT Id, Name, Status ORDER BY Name';
// Create paging controls.
$totalNumEntries = 0;
$offset = 0;
do {
$pageQuery = sprintf('%s LIMIT %d,%d', $query, $offset, self::PAGE_LIMIT);
// Make the query request.
$page = $campaignService->query($pageQuery);
// Display results from the query.
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $campaign) {
printf(
"Campaign with ID %d and name '%s' was found.\n",
$campaign->getId(),
$campaign->getName()
);
}
}
// Advance the paging offset.
$offset += self::PAGE_LIMIT;
} while ($offset < $totalNumEntries);
printf("Number of results found: %d\n", $totalNumEntries);
}
public static function main() {
$KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';
// OAuth2TokenBuilder
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile($KEY_FILE_LOCATION)
->build();
// Construct an API session configured from a properties file and the OAuth2
// credentials above.
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
self::runExample(new AdWordsServices(), $session);
}
我使用了Google的一个示例,但仍然遇到同样的错误,我无法解决该错误。 有什么建议,链接?提前谢谢!