more examples for php google ads api recommendations type

267 views
Skip to first unread message

Shiv Kumar

unread,
May 4, 2020, 7:31:32 PM5/4/20
to AdWords API and Google Ads API Forum
It would be great if someone point me to the PHP client library documentation for google ads API for retrieving data for all recommendation types.

I really find it hard as the basic examples provided or the documentation of the API or the PHP library doesn't even specify which class methods to use to retrieve data for example for recommendation type 'KEYWORD'.

Google Ads API Forum Advisor Prod

unread,
May 5, 2020, 10:06:46 AM5/5/20
to shivkumar...@gmail.com, adwor...@googlegroups.com
Hi Shiv,

Thank you for reaching out. You can see here for an example of getting all Text Ad recommendations. This example uses the recommendation report so you can modify it by using the different attributes listed there. For example, to get recommendations of type KEYWORD, you can change 'WHERE recommendation.type = TEXT_AD' to be 'WHERE recommendation.type = KEYWORD' and make sure you add recommendation.keyword_recommendation to your SELECT clause. You can find the available recommendation types for the report here.

Regards,
Mitchell
Google Ads API Team

ref:_00D1U1174p._5004Q1zK8TD:ref

Shiv Kumar

unread,
May 5, 2020, 1:15:37 PM5/5/20
to AdWords API and Google Ads API Forum
The issue I am facing is that the google PHP library wrapper doesn't tell which function to use for each type of recommendation report for example : 

foreach ($response->iterateAllElements() as $googleAdsRow) {
            /** @var GoogleAdsRow $googleAdsRow */
            $recommendation = $googleAdsRow->getRecommendation();

$recommendedAd = $recommendation->getKeywordRecommendation()->getKeyword();
                
 if (!is_null($recommendedAd->getText())) {
    $recommendedExpandedTextAd = $recommendedAd->getText();


}


So above code sample shows use of "$recommendation->getKeywordRecommendation()->getKeyword();" these 2 functions on the retrieved data object, I had to guess these function names as there was no mention in PHP wrapper for the API neither in the google ads doc. So I was hoping there are more examples for other recommendation report types so I don't have to guess the function names.

Shiv Kumar

unread,
May 5, 2020, 1:21:31 PM5/5/20
to AdWords API and Google Ads API Forum
Also in the above code example I do not know how to match `$recommendedAd->getMatchType()` numeric value to its actual text value like (2=> Exact, 4 => Broad).

Google Ads API Forum Advisor Prod

unread,
May 6, 2020, 9:46:27 AM5/6/20
to shivkumar...@gmail.com, adwor...@googlegroups.com
Hi Shiv,

For your first question, you can find this information in the resource of the desired recommendation type. For the example of keyword recommendations, you can retrieve the values available in KeywordRecommendation and for text ad recommendations, TextAdRecommendation.

To understand the numeric value of the match types, you can see here. The enums folder contains all of the protos for different resources.

Shiv Kumar

unread,
May 9, 2020, 1:15:55 PM5/9/20
to AdWords API and Google Ads API Forum
Thank you for the enums list, it solved most of the issues I had, but there is a function getType() which always returns 11 integer value and I can't relate to it for the label part.
For example 

foreach ($response->iterateAllElements() as $googleAdsRow) {
            /** @var GoogleAdsRow $googleAdsRow */
            $recommendation = $googleAdsRow->getRecommendation();

            $recommendedAd
= $recommendation->getTargetCpaOptInRecommendation();    
            echo $recommendedAd = $recommendation->getTargetCpaOptInRecommendation()->getOptions()->getType();###ALWAYS PRINTS 11

}



Also I got struct while trying to display data for SITELINK_EXTENSION type recommendation.

How do I extract information for this type, I do see some methods like

 $recommendedAd = $recommendation->getSitelinkExtensionRecommendation();
                   
 print_r(get_class_methods($recommendedAd->getRecommendedExtensions()->getClass() ));
 echo "<br>getLine1Unwrapped: " . print_r($recommendedAd->getRecommendedExtensions()->getClass()->getLine1Unwrapped() );


But they give me error that `Uncaught Error: Call to a member function getLine1Unwrapped() on string`. 

For recommendation type "SEARCH_PARTNERS_OPT_IN" I do not see any get function that can be used to extract data, is that the case?

Google Ads API Forum Advisor Prod

unread,
May 11, 2020, 10:27:20 AM5/11/20
to shivkumar...@gmail.com, adwor...@googlegroups.com
Hi Shiv,

I'm glad the protos helped! For your first issue, could you please provide the complete detailed request and response logs for the call via Reply privately to author so I can further investigate the issue? You can find information on enabling logging here.

For the sitelink extension recommendations, you should getRecommendedExtensions like you already did and from there, you can pull the specific attributes of the sitelink that is recommended such as the link_text or line1/line2. The attributes are listed here.

For the search partners opt in recommendation, there is no information to extract other than the campaign ID since the recommendation is simply telling you to opt into search partners for that specific campaign.

Shiv Kumar

unread,
May 11, 2020, 10:58:08 AM5/11/20
to AdWords API and Google Ads API Forum
I tried 
$recommendedAd->getRecommendedExtensions()->getLine1Unwrapped();//##`Fatal error:  Uncaught Error: Call to undefined method Google\Protobuf\Internal\RepeatedField::getLine1Unwrapped()`

which doesn't show that method linked, however if I use `$recommendedAd->getRecommendedExtensions()->getClass()` it does show that method available but I do not know how to call it as doing
 `$recommendedAd->getRecommendedExtensions()->getClass()->getLine1Unwrapped()' produces
Uncaught Error: Call to a member function getLine1Unwrapped() on string.

Kind of struct here, am I missing something?

Google Ads API Forum Advisor Prod

unread,
May 11, 2020, 4:05:16 PM5/11/20
to shivkumar...@gmail.com, adwor...@googlegroups.com
Hi Shiv,

This issue appears to be related to the client library so I would recommend posting it on the GitHub Issues page here. Their team will be more equipped to assist you.
Reply all
Reply to author
Forward
0 new messages