获取 Google Ads API keywords_plan_idea_error:输入的值无效

发布于 2025-01-11 06:46:53 字数 715 浏览 0 评论 0原文

$requestOptionalArgs = [];
$requestOptionalArgs['keywordSeed'] = new KeywordSeed(['keywords' => $keywords]);
$keywordPlanIdeaServiceClient->generateKeywordIdeas([
                                'language' => ResourceNames::forLanguageConstant(1000), // English
                                'customerId' => $customerId,
                                'geoTargetConstants' => $geoTargetConstants,
                                'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH
                            ] + $requestOptionalArgs);

如果 $keywords 数组大小不超过 20,上面的代码可以正常工作。如果我将第 21 个关键字添加到 $keywords 数组,则会抛出以下错误。 keyword_plan_idea_error:输入的值无效。

$requestOptionalArgs = [];
$requestOptionalArgs['keywordSeed'] = new KeywordSeed(['keywords' => $keywords]);
$keywordPlanIdeaServiceClient->generateKeywordIdeas([
                                'language' => ResourceNames::forLanguageConstant(1000), // English
                                'customerId' => $customerId,
                                'geoTargetConstants' => $geoTargetConstants,
                                'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH
                            ] + $requestOptionalArgs);

The above code is working fine if the $keywords array size is not more than 20. If I add the 21st keyword to the $keywords array then it's throwing the below error.
keyword_plan_idea_error: The input has an invalid value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

殤城〤 2025-01-18 06:46:53

Google Ads API 每个请求最多可使用 20 个关键字。您需要将关键字分成块并循环遍历它们。

像这样的东西:

<?php

$keywords = [];

// Create multiple arrays to pass through Google Ads API
$chunk = array_chunk($keywords, 20, true);

foreach ($chunk as $piece) {

    $requestOptionalArgs = [];

    $requestOptionalArgs['keywordSeed'] = new KeywordSeed(['keywords' => $piece]);

    $keywordPlanIdeaServiceClient->generateKeywordIdeas([
         'language' => ResourceNames::forLanguageConstant(1000), // English
         'customerId' => $customerId,
         'geoTargetConstants' => $geoTargetConstants,
         'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH
    ] + $requestOptionalArgs);

}

Google Ads API has a limit of 20 keywords per request. You'll need to separate your keywords into chunks and loop through them.

Something like this:

<?php

$keywords = [];

// Create multiple arrays to pass through Google Ads API
$chunk = array_chunk($keywords, 20, true);

foreach ($chunk as $piece) {

    $requestOptionalArgs = [];

    $requestOptionalArgs['keywordSeed'] = new KeywordSeed(['keywords' => $piece]);

    $keywordPlanIdeaServiceClient->generateKeywordIdeas([
         'language' => ResourceNames::forLanguageConstant(1000), // English
         'customerId' => $customerId,
         'geoTargetConstants' => $geoTargetConstants,
         'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH
    ] + $requestOptionalArgs);

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文