google adwords api +获取所有关键字

时间:2010-10-24 12:13:01

标签: google-adwords

我正在使用google adwords api,我可以检索所有广告系列,分组广告,广告, 但我不知道如何检索与“群组广告”相关的关键字。 在Google adwords界面中,当我们选择群组广告时,我们有两个标签,一个用于与该群组广告相关的广告,另一个用于关键字。 但是以编程方式,我现在只能检索广告。 我正在使用PHP,如果有人知道如何在PHP或其他编程语言中进行操作,甚至是肥皂调用。

2 个答案:

答案 0 :(得分:4)

在Adwords API中,关键字被称为广告组标准。您可以使用AdGroupCriterionService添加或检索特定广告组的关键字。

如果您使用的是Adwords API的PHP客户端库,请在示例文件中查看GetAllAdGroupCriteria.php。 (不要忘记输入您想要首先获得关键字的AdGroupId)

答案 1 :(得分:4)

要获取广告组所有关键字的详细信息,您需要执行以下操作以获取所有关键字的详细信息。  

require_once dirname(dirname(__FILE__)) . '/init.php';

// Enter parameters required by the code example.
$adGroupId = 'Enter your adgroup id';

/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $adGroupId the id of the parent ad group
 */
function GetKeywordsExample(AdWordsUser $user, $adGroupId) {
  // 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');
  $selector->ordering[] = new OrderBy('KeywordText', 'ASCENDING');

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

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

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

    // Display results.
    if (isset($page->entries)) {
      foreach ($page->entries as $adGroupCriterion) {
      printf("Keyword with text '%s', match type '%s', and ID '%s' was "
          . "found.\n", $adGroupCriterion->criterion->text,
          $adGroupCriterion->criterion->matchType,
          $adGroupCriterion->criterion->id);
      }
    } else {
      print "No keywords were found.\n";
    }

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

// Don't run the example if the file is being included.
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
  return;
}

try {
  // Get AdWordsUser from credentials in "../auth.ini"
  // relative to the AdWordsUser.php file's directory.
  $user = new AdWordsUser();

  // Log every SOAP XML request and response.
  $user->LogAll();

  // Run the example.
  GetKeywordsExample($user, $adGroupId);
} catch (Exception $e) {
  printf("An error has occurred: %s\n", $e->getMessage());
}