I want to use Google AdWords API to get monthly search volume and CPC for some keywords with PHP. The API itself made me so confused, and the more I read documentations and forum threads and questions and answers, the more confused I got.
Can anyone please explain how it works to me in a really really simple way, and tell me how to make it up and running step by step?
Thanks in advance.
Yes, here is an example file to get a list of keywords and volume.
function GetKeywordIdeasExample(AdWordsUser $user) {
// Get the service, which loads the required classes.
$targetingIdeaService =
$user->GetService('TargetingIdeaService', ADWORDS_VERSION);
// Create seed keyword.
$keyword = 'mars cruise';
// Create selector.
$selector = new TargetingIdeaSelector();
$selector->requestType = 'IDEAS';
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME',
'CATEGORY_PRODUCTS_AND_SERVICES');
// Create language search parameter (optional).
// The ID can be found in the documentation:
// https://developers.google.com/adwords/api/docs/appendix/languagecodes
// Note: As of v201302, only a single language parameter is allowed.
$languageParameter = new LanguageSearchParameter();
$english = new Language();
$english->id = 1000;
$languageParameter->languages = array($english);
// Create related to query search parameter.
$relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
$relatedToQuerySearchParameter->queries = array($keyword);
$selector->searchParameters[] = $relatedToQuerySearchParameter;
$selector->searchParameters[] = $languageParameter;
// Set selector paging (required by this service).
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
do {
// Make the get request.
$page = $targetingIdeaService->get($selector);
// Display results.
if (isset($page->entries)) {
foreach ($page->entries as $targetingIdea) {
$data = MapUtils::GetMap($targetingIdea->data);
$keyword = $data['KEYWORD_TEXT']->value;
$search_volume = isset($data['SEARCH_VOLUME']->value)
? $data['SEARCH_VOLUME']->value : 0;
$categoryIds =
implode(', ', $data['CATEGORY_PRODUCTS_AND_SERVICES']->value);
printf("Keyword idea with text '%s', category IDs (%s) and average "
. "monthly search volume '%s' was found.\n",
$keyword, $categoryIds, $search_volume);
}
} else {
print "No keywords ideas were found.\n";
}
// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
}
Here is sample output using the TrafficEstimatorService, not the similar TargetingIdeaService above.
Keyword: cooling capacity window, match: EXACT, cpc: $0.00, vol: 0
Keyword: capacity window air, match: EXACT, cpc: $0.00, vol: 0
Keyword: oral-b professional deep sweep 4000 electric rechargeable toothbrush, match: EXACT, cpc: $0.00, vol: 0
Keyword: oral, match: EXACT, cpc: $0.00, vol: 347
Keyword: professional, match: EXACT, cpc: $0.00, vol: 721
Keyword: sweep, match: EXACT, cpc: $0.00, vol: 101
Keyword: toothbrush, match: EXACT, cpc: $0.16, vol: 17746
Keyword: oral b, match: EXACT, cpc: $0.26, vol: 17768
Keyword: b professional, match: EXACT, cpc: $0.00, vol: 0
来源:https://stackoverflow.com/questions/23424564/use-google-adwords-api-with-php-to-get-keyword-cpc-and-monthly-search-volume