get keyword status from getkeywords api in php

156 views
Skip to first unread message

Bhairavi

unread,
Jan 30, 2018, 3:26:24 AM1/30/18
to AdWords API Forum
I am using google adwords client library for php.I am using getKeywords api to fetch keywords and related info.How to get keyword status in api.
I have added 'Status' in selector field as follows-
 $selector->setFields(
        ['Id', 'CriteriaType', 'KeywordMatchType', 'KeywordText','Status']);

but how to get status in foreach loop : 
 foreach ($page->getEntries() as $adGroupCriterion) {
                   
//how to get status
                 
                }

Peter Oliquino

unread,
Jan 30, 2018, 5:25:37 AM1/30/18
to AdWords API Forum
Hi,

Since you have already included the Status field in your selector, you will just need to include the sample code snippet below inside your loop :

$adGroupCriterion->getCriterion()->getStatus();

This will then allow to retrieve the information for your BiddableAdGroupCriterion's (Keyword etc.) status.

Best regards,
Peter
AdWords API Team

Peter Oliquino

unread,
Jan 31, 2018, 1:49:17 AM1/31/18
to AdWords API Forum
Hi,

My apologies for the confusion and allow me to update my previous response. Also, for the benefit of those following our thread, I will be responding publicly to your follow up question regarding my previous suggestion not working as expected.

From the results that you will retrieve or for every iteration, you will also need to cast the object as a BiddableAdGroupCriterion and add the getUserStatus() to retrieve its Status information. It should then correspond to the status of the Keyword criterion which you are trying to retrieve. Below is the sample code (in Java) that I used to achieve this :

 for (AdGroupCriterion adGroupCriterionResult : page.getEntries()) {
         
         BiddableAdGroupCriterion bidCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
         System.out.println(bidCriterion.getUserStatus());
         
         Keyword keyword = (Keyword) adGroupCriterionResult.getCriterion();
         System.out.printf(
             "Keyword with text '%s', match type '%s', criteria type '%s', and ID %d was found.%n",
             keyword.getText(), keyword.getMatchType(), keyword.getType(), keyword.getId());
       }

Let me know if this already works.
Reply all
Reply to author
Forward
0 new messages