我想出了如何创建和删除关键字计划,但我不知道如何获得所有现有关键字计划(资源名称/计划I)的列表。
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
任何关于如何解决这个问题的提示都是非常感谢的!事先非常感谢!
发布于 2022-03-28 13:28:24
也许您可以尝试从您的帐户中获取keyword_plan资源。我就是这样为所有现有的keywordPlans创建删除操作的。
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());当然,这也可以应用于您的用例。
发布于 2022-03-29 05:43:30
如果您想删除所有现有的关键字计划,这是针对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]);
}发布于 2022-10-19 12:41:57
对于python:
import argparse
import sys
from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException
def main(client, customer_id):
ga_service = client.get_service("GoogleAdsService")
query = """
SELECT keyword_plan.name, keyword_plan.id, keyword_plan.forecast_period, keyword_plan.resource_name
FROM keyword_plan
"""
# Issues a search request using streaming.
search_request = client.get_type("SearchGoogleAdsStreamRequest")
search_request.customer_id = customer_id
search_request.query = query
stream = ga_service.search_stream(search_request)
for batch in stream:
for row in batch.results:
resource_name = row.keyword_plan.resource_name
forecast_period = row.keyword_plan.forecast_period
id = row.keyword_plan.id
name = row.keyword_plan.name
print(
f'plan resource name "{resource_name}" with '
f'forecast period "{forecast_period.date_interval}" '
f"and ID {id} "
f' name "{name}" '
)
if __name__ == "__main__":
# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
googleads_client = GoogleAdsClient.load_from_storage(path='your-google-ads.yml-file-path',version="v10")
parser = argparse.ArgumentParser(
description=("Retrieves a campaign's negative keywords.")
)
# The following argument(s) should be provided to run the example.
parser.add_argument(
"-c",
"--customer_id",
type=str,
required=True,
help="The Google Ads customer ID.",
)
args = parser.parse_args()
try:
main(googleads_client, args.customer_id)
except GoogleAdsException as ex:
print(
f'Request with ID "{ex.request_id}" failed with status '
f'"{ex.error.code().name}" and includes the following
errors:'
)
for error in ex.failure.errors:
print(f'\tError with message "{error.message}".')
if error.location:
for field_path_element in error.location.field_path_elements:
print(f"\t\tOn field: {field_path_element.field_name}")
sys.exit(1)https://stackoverflow.com/questions/70041224
复制相似问题