Get All keywords in Adword v200909 in PHP
I hope this will help you guys when working with adword new API. I just completed this function and thought of sharing it for you all. I couldn’t find any PHP code in the net to do the same.
Cheers,
Priya.
——————————————————————
class GetAllKeywordsExample {
static function main($keywords_input, $match_type) {
$return_array = array();
try {
// Get AdWordsUser from credentials in “../auth.ini”
// relative to the AdWordsUser.php file’s directory.
$user = new AdWordsUser();
// Log SOAP XML request and response.
$user->LogDefaults();
// Get the TargetingIdeaService.
$keywordService = $user->GetTargetingIdeaService();
$keyword = new Keyword();
$keyword->text = $keywords_input;
$keyword->matchType = $match_type;
$keyword_array = array($keyword);
$relatedToKeywordSearchParameter = new RelatedToKeywordSearchParameter($keyword_array);
$targetingIdeaSelector = new TargetingIdeaSelector();
$targetingIdeaSelector->searchParameters = array(
$relatedToKeywordSearchParameter
);
$targetingIdeaSelector->ideaType = ‘KEYWORD’;
$targetingIdeaSelector->requestType = ‘IDEAS’;
$targetingIdeaSelector->paging = new Paging(0,800);
// Get all Keywords.
$keywordPage = $keywordService->get($targetingIdeaSelector);
// Prepare keyword array.
if(isset($keywordPage->entries)) {
foreach ($keywordPage->entries as $keyword_entry) {
foreach($keyword_entry as $keyword_entry_array){
/*
*/
//var_dump($keyword);
foreach ($keyword_entry_array as $keyword){
if($keyword->key == ‘KEYWORD’){
$keyword_value = $keyword->value;
if($keyword_value->value->matchType == $match_type){
$return_array[] = array(
‘keyword’=>$keyword_value->value->text
);
}
}
}
}
}
} else {
throw new Exception(”ERROR”,0);
}
} catch (Exception $e) {
$return_array[] = array(
‘keyword’=>$e->getMessage());
}
return $return_array;
}
}
——————————————————-
#1 Posted by rayden (05.11.09 at 03:31 )
Thank so much for this. Very helpfull. You have any other examples, maybe? Best regards, Luka
#2 Posted by rolo2912 (17.11.09 at 02:43 )
Hi,
Thank you so much for providing this working example. Finally I made some progress on the 2009 API. Still getting errors so. Just wondering, do you have any idea why I get this error message :
Array ( [‘keyword’] => SOAP-ERROR: Encoding: string ‘\x91…’ is not a valid utf-8 string ) )
#3 Posted by rolo2912 (17.11.09 at 02:55 )
ok, sorry. This was a copy/paste error. All the ””" were not correctly pasted in. Fixed now. Sad to say but I am receiving this error now :
[RequiredError.REQUIRED @ selector.searchParameters[0].keywords[0].matchType] ) )
Does this make sence to anybody ?
#4 Posted by Priyantha (17.11.09 at 11:25 )
you may have missed the matchType for sure. $keyword->matchType = $match_type; please assign the correct values
#5 Posted by jawahar (18.11.09 at 00:45 )
Hi Priya
Can you post the full code? Right from the auth? And also how to fetch the results..??
Am relatively new to the adwords API.. so it will be very helpful ?
Regs
Jawahar
#6 Posted by Priyantha (18.11.09 at 06:49 )
visit the google group for google adword I have posted some working samples in there. This link should direct you in there
Leave a Comment

















6 Comments to “Get All keywords in Adword v200909 in PHP”