gpt4 book ai didi

php - Google Adwords API 的问题

转载 作者:搜寻专家 更新时间:2023-10-31 21:55:35 25 4
gpt4 key购买 nike

我正在使用 Google Adwords API (v201109) 获取关键字及其搜索量。我已经创建了文件

adwords.php 包含以下代码 -

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

$path = dirname(__FILE__) . '/../../../';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';

$adwords_username = "myusername@gmail.com";
$adwords_password = "mypassword";
$adwords_developerToken = "mydevelopertoken";
$user = new AdWordsUser(null, $adwords_username, $adwords_password, $adwords_developerToken);
$user->SetDefaultServer("https://adwords.google.com/");

//set Adwords Client Id
$user->SetClientCustomerId('111111111');

$str_group = GetAdGroup($user, "v201509");
echo $str_group;

function GetAdGroup(AdWordsUser $user, $adwords_version) {
// Get the service, which loads the required classes.
$adgroupService = $user->GetService('AdGroupService', $adwords_version);

// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'Name', 'CampaignId', 'Status');
$selector->ordering[] = new OrderBy('CampaignId', 'ASCENDING');

// Filter out deleted criteria.
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DELETED', 'PAUSED'));

// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

$ret = array();
do {
//echo "<pre>";print_r($selector);die;
// Make the get request.
$page = $adgroupService->get($selector);

// Display results.
if (isset($page->entries)) {
foreach ($page->entries as $adgroup) {
//printf("AdGroup with name '%s' and id '%s' was found for Campaign: '%s' and Status: '%s'\n",
// $adgroup->name, $adgroup->id, $adgroup->campaignId, $adgroup->status);
$ret[] = array(
'name' => $adgroup->name,
'id' => $adgroup->id,
'campaignId' => $adgroup->campaignId,
'active' => (strcmp($adgroup->status,'ENABLED')==0)?1:0
);
}
} else {
//print "No adgroups were found.\n";
}
// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
return $ret;
}

function GetKeywords(AdWordsUser $user, $adGroupId, $days, $adwords_version) {
// Get the service, which loads the required classes.
$adGroupCriterionService = $user->GetService('AdGroupCriterionService', $adwords_version);

// Create selector.
$selector = new Selector();

$selector->fields = array('KeywordText', 'KeywordMatchType', 'Id', 'AverageCpc', 'AveragePosition', 'Clicks', 'Conversions', 'Cost', 'Ctr', 'Impressions', 'QualityScore', 'Status');
$selector->ordering[] = new OrderBy('KeywordText', 'ASCENDING');

// Create predicates.
$selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId));
$selector->predicates[] = new Predicate('CriteriaType', 'IN', array('KEYWORD'));
$selector->predicates[] = new Predicate('Status', 'IN', array('ACTIVE'));
$selector->predicates[] = new Predicate('Impressions', 'GREATER_THAN', array('1'));

$dateRange = new DateRange();
$str1 = '-1 days';
$str2 = '-1 days';
if ($days > 0) {
$str1 = '-' . $days . ' days';
$str2 = '-' . $days . ' days';
}
$dateRange->min = date('Ymd', strtotime($str1));
$dateRange->max = date('Ymd', strtotime($str2));
$selector->dateRange = $dateRange;

// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

$ret = array();

do {
// Make the get request.
$page = $adGroupCriterionService->get($selector);

// Display results.
if (isset($page->entries)) {
foreach ($page->entries as $adGroupCriterion) {
$cr = 0;
if ($adGroupCriterion->stats->clicks > 0)
$cr = $adGroupCriterion->stats->conversions / $adGroupCriterion->stats->clicks;

$ret[] = array(
'name' => $adGroupCriterion->criterion->text,
'type' => $adGroupCriterion->criterion->matchType,
'id' => $adGroupCriterion->criterion->id,
'clicks' => $adGroupCriterion->stats->clicks,
'cpc' => $adGroupCriterion->stats->averageCpc->microAmount / 1000000,
'conversions' => $adGroupCriterion->stats->conversions,
'cost' => $adGroupCriterion->stats->cost->microAmount / 1000000,
'ctr' => $adGroupCriterion->stats->ctr,
'impressions' => $adGroupCriterion->stats->impressions,
'qualityfactor' => $adGroupCriterion->qualityInfo->qualityScore,
'cr' => $cr,
'position' => $adGroupCriterion->stats->averagePosition
);
}
} else {
//print "No keywords were found.\n";
}

// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
return $ret;
}

但是当我运行 adwords.php 文件时,我不断收到以下错误。

错误

Fatal error: Uncaught SoapFault exception: [soap:Server] [QuotaCheckError.INVALID_TOKEN_HEADER @ ; trigger:'abhijeetk.aloha@gmail.com'] in /var/www/html/Google/Api/Ads/Common/Lib/AdsSoapClient.php:216 Stack trace: #0 /var/www/html/Google/Api/Ads/Common/Lib/AdsSoapClient.php(216): SoapClient->__soapCall('get', Array, NULL, Array, Array) #1 /var/www/html/Google/Api/Ads/AdWords/v201509/AdGroupService.php(7408): AdsSoapClient->__soapCall('get', Array) #2 /var/www/html/adwords.php(46): AdGroupService->get(Object(Selector))

3 /var/www/html/adwords.php(22): GetAdGroup(Object(AdWordsUser), 'v201509') #4 {main} thrown in

/var/www/html/Google/Api/Ads/Common/Lib/AdsSoapClient.php on line 216

我是新手,所以我不知道如何使用 API 获取数据,请告诉我我做错了什么。或者我如何使用 adwords API 获取关键字及其数量和其他数据。我找到的所有文档让我更加困惑。

提前致谢

最佳答案

__construct($authenticationIniPath = null,
$developerToken = null, $userAgent = null, $clientCustomerId = null,
$settingsIniPath = null, $oauth2Info = null)

$user = new AdWordsUser(null, $adwords_username, $adwords_password, $adwords_developerToken);

传递了错误的数据;请改用 auth.ini。 https://developers.google.com/adwords/api/docs/first-request

关于php - Google Adwords API 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34285969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com