Skip to content

Instantly share code, notes, and snippets.

@anvius
Last active December 1, 2015 16:36
Show Gist options
  • Save anvius/7950da8620aa24ad214b to your computer and use it in GitHub Desktop.
Save anvius/7950da8620aa24ad214b to your computer and use it in GitHub Desktop.
Keyword competition adwords
<?php
$user = new AdWordsUser();
$user->LogDefaults();
$targetingIdeaService = $user->GetService('TargetingIdeaService', 'v201402');
$keyword = 'mars cruise';
$selector = new TargetingIdeaSelector();
$selector->requestType = 'STATS';
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = array('COMPETITION');
// code below give this exception: Unmarshalling Error: cvc-type.2: The type definition cannot be abstract for element ns1:searchParameters.
$relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
$relatedToQuerySearchParameter->queries = array($keyword);
$selector->searchParameters[] = $relatedToQuerySearchParameter;
//if do not use code above I have this error: [AuthenticationError.OAUTH_TOKEN_INVALID @ ; trigger:'']
//could it be because my developer token is not registred yet?
// Set selector paging (required by this service).
$selector->paging = new Paging(0, 10);
do {
// code below gives this warning: Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /googleads-php-lib-master/src/Google/Api/Ads/Common/Util/CurlUtils.php on line 107
$page = $targetingIdeaService->get($selector);
if (isset($page->entries)) {
foreach ($page->entries as $targetingIdea) {
$data = MapUtils::GetMap($targetingIdea->data);
$competition =
isset($data['COMPETITION']->value)
? $data['COMPETITION']->value : 0;
echo($competition);
}
} else {
print "No keywords ideas were found.\n";
}
$selector->paging->startIndex += 10;
} while ($page->totalNumEntries > $selector->paging->startIndex);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment