Hi,

I want to use Targeting Ideas like Keyword Planner. I tried this code but 
got an error. How can i solve this?

Error: [TargetingIdeaError.INSUFFICIENT_SEARCH_PARAMETERS @ 
selector.searchParameters]

*Code:*

$adWordsServices = new AdWordsServices();
$session = main('XXX-XXX-XXXX');
$targetingIdeaService = $adWordsServices->get($session, 
TargetingIdeaService::class);

$selector = new TargetingIdeaSelector();
$selector->setRequestType(RequestType::IDEAS);
$selector->setIdeaType(IdeaType::KEYWORD);
$selector->setRequestedAttributeTypes(
      [
           AttributeType::KEYWORD_TEXT,
           AttributeType::SEARCH_VOLUME,
           AttributeType::AVERAGE_CPC,
           AttributeType::COMPETITION,
           AttributeType::CATEGORY_PRODUCTS_AND_SERVICES
       ]
);
$paging = new Paging();
$paging->setStartIndex(0);
$paging->setNumberResults(10);
$selector->setPaging($paging);
$searchParameters = [];
$relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
$relatedToQuerySearchParameter->setQueries(
     [
               'iphone 11 pro max'
     ]
);

$searchParameters[] = $relatedToQuerySearchParameter;

$page = $targetingIdeaService->get($selector);
   
   $entries = $page->getEntries();
if ($entries !== null) {
   foreach ($entries as $targetingIdea) {
       $data = MapEntries::toAssociativeArray($targetingIdea->getData());
       $keyword = $data[AttributeType::KEYWORD_TEXT]->getValue();
       $searchVolume = ($data[AttributeType::SEARCH_VOLUME]->getValue() !== 
null)
           ? $data[AttributeType::SEARCH_VOLUME]->getValue() : 0;
       $averageCpc = $data[AttributeType::AVERAGE_CPC]->getValue();
       $competition = $data[AttributeType::COMPETITION]->getValue();
       $categoryIds = 
($data[AttributeType::CATEGORY_PRODUCTS_AND_SERVICES]->getValue() === null)
           ? $categoryIds = ''
           : implode(
               ', ',
              
 $data[AttributeType::CATEGORY_PRODUCTS_AND_SERVICES]->getValue()
           );
       printf(
           "Keyword with text '%s', average monthly search volume %d, "
           . "average CPC %d, and competition %.2f was found with 
categories: %s\n",
           $keyword,
           $searchVolume,
           ($averageCpc === null) ? 0 : $averageCpc->getMicroAmount(),
           $competition,
           $categoryIds
       );
   }
}

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/3a3b9c80-6a7f-49d2-9e8e-b42e50918836n%40googlegroups.com.

Reply via email to