GoogleAds API - Java / 如何获取所有现有的关键字计划?

GoogleAds API - Java / How to get all existing Keyword Plans?

我想出了如何创建和删除关键字计划,但我不知道如何获得所有现有关键字计划(资源名称/计划 ID)的列表?

final long customerId = Long.valueOf("XXXXXXXXXX");    
GoogleAdsClient googleAdsClient = new ...
KeywordPlanServiceClient client = googleAdsClient.getVersion8().createKeywordPlanServiceClient();

String[] allExistingKeywordPlans = client. ???

<dependency>
    <groupId>com.google.api-ads</groupId>
    <artifactId>google-ads</artifactId>
    <version>16.0.0</version>
</dependency>

更多资源: https://developers.google.com/google-ads/api/docs/samples/add-keyword-plan

非常感谢有关如何解决此问题的任何提示!非常感谢!

也许您可以尝试从您的帐户中获取 keyword_plan 资源。 这就是我为所有现有关键字计划创建删除操作的方法。

GoogleAdsServiceClient.SearchPagedResponse response = client.search(SearchGoogleAdsRequest.newBuilder()
                    .setQuery("SELECT keyword_plan.resource_name FROM keyword_plan")
                    .setCustomerId(Objects.requireNonNull(googleAdsClient.getLoginCustomerId()).toString())
                    .build());
List<KeywordPlanOperation> keywordPlanOperations = response.getPage().getResponse().getResultsList().stream()
                    .map(x -> KeywordPlanOperation.newBuilder()
                            .setRemove(x.getKeywordPlan().getResourceName())
                            .build())
                    .collect(Collectors.toList());

当然这也适用于你的use-case。

如果您想删除所有现有的关键字计划,这适用于 PHP:

$googleAdsServiceClient = $this->googleAdsClient->getGoogleAdsServiceClient();

/** @var GoogleAdsServerStreamDecorator $stream */
$stream = $googleAdsServiceClient->searchStream(
    $linkedCustomerId,
    'SELECT keyword_plan.resource_name FROM keyword_plan'
);

$keywordPlanServiceClient = $this->googleAdsClient->getKeywordPlanServiceClient();

/** @var GoogleAdsRow $googleAdsRow */
foreach ($stream->iterateAllElements() as $googleAdsRow) {

    $keywordPlanOperation = new KeywordPlanOperation();
    $keywordPlanOperation->setRemove($googleAdsRow->getKeywordPlan()->getResourceName());
    $keywordPlanServiceClient->mutateKeywordPlans($this->linkedCustomerId, [$keywordPlanOperation]);
}