Use Google AdWords API with PHP to get keyword CPC and monthly search volume

纵然是瞬间 提交于 2019-12-06 08:35:12

Yes, here is an example file to get a list of keywords and volume.

https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201502/Optimization/GetKeywordIdeas.php

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!