Does anyone have working generateforecastmetrics() code yet?

53 views
Skip to first unread message

Patrick P

unread,
Jun 23, 2023, 10:36:51 AM6/23/23
to Google Ads API and AdWords API Forum
I'm still trying to get generateforecastmetrics() working in the v14 php sdk 

This code is segfaulting for me when trying to instantiate the BiddableKeyword object

$KeywordPlanIdeaServiceClient = $googleAdsClient->getKeywordPlanIdeaServiceClient();

        $biddableKeywords = new BiddableKeyword([
            'keyword' => new KeywordInfo([
                            'text' => 'houston homes for sale',
                            'match_type' => KeywordMatchType::BROAD
            ])
        ]);

        $forecastAdGroup = new ForecastAdGroup([$biddableKeywords]);

        $keywordPlanCampaign = new CampaignToForecast([
            'ad_groups' => [$forecastAdGroup],
        ]);

        $reqArr = array(
            "customerId" => $customerId,
            "currencyCode" => "USD",
            "forecastPeriod" => array(
                "start_date" => "2023-07-01",
                "end_date" => "2023-06-30"
            )
        );
       
        $generateKeywordForecastMetricsResponse = $KeywordPlanIdeaServiceClient->generateKeywordForecastMetrics($keywordPlanCampaign, $reqArr);


output:

root@laravel-playground:/var/www/sdks/google-ads-php/examples/Planning# php8.1 AddKeywordPlan.php
Created keyword plan: 'customers/8750204858/keywordPlans/719125200'
Created campaign for keyword plan: 'customers/8750204858/keywordPlanCampaigns/669754323'
Created ad group for keyword plan: 'customers/8750204858/keywordPlanAdGroups/701291997'
Segmentation fault (core dumped)


Google rep: it's been 3 weeks since you've deprecated the old methods, can you please supply us with a working example?



Patrick P

unread,
Jun 23, 2023, 10:53:30 AM6/23/23
to Google Ads API and AdWords API Forum
Followup:

I did get this working in the API explorer using the REST API so I think I'm just going to ditch the php SDK since the support is so bad

Here was the request payload that worked for me:
{
  "campaign": {
    "adGroups": [
      {
        "biddableKeywords": [
          {
            "keyword": {
              "matchType": "BROAD",
              "text": "houston homes for sale"
            }
          }
        ],
        "maxCpcBidMicros": 5000000
      }
    ],
    "keywordPlanNetwork": "GOOGLE_SEARCH"
  },
  "forecastPeriod": {
    "endDate": "2023-07-30",
    "startDate": "2023-07-01"
  }
}

Returning:
{
  "campaignForecastMetrics": {
    "impressions": 21333.228515625,
    "clickThroughRate": 0.17527243494987488,
    "averageCpcMicros": "1550281",
    "clicks": 3739.126953125,
    "costMicros": "5796696000",
    "conversions": 226.53358459472656,
    "conversionRate": 0.060584619641304016,
    "averageCpaMicros": "25588682"
  }
}

Patrick P

unread,
Jun 23, 2023, 11:03:05 AM6/23/23
to Google Ads API and AdWords API Forum
Another followup, here is the working curl with the token, customer ID & dev token redacted:

curl 'https://content-googleads.googleapis.com/v14/customers/8750204858:generateKeywordForecastMetrics' \
-H 'Developer-Token: DEVTOKENREDACTED\
-H 'Login-Customer-Id: LOGINCUSTOMERIDREDACTED\
-H 'Content-Type: text/plain' \
-H 'Authorization: ACCESSTOKENREDACTED' \
-d '{

  "campaign": {
    "adGroups": [
      {
        "biddableKeywords": [
          {
            "keyword": {
              "matchType": "BROAD",
              "text": "houston homes for sale"
            }
          }
        ],
        "maxCpcBidMicros": 5000000
      }
    ],
    "keywordPlanNetwork": "GOOGLE_SEARCH"
  },
  "forecastPeriod": {
    "endDate": "2023-07-30",
    "startDate": "2023-07-01"
  }
}'

Response:

Google Ads API Forum Advisor

unread,
Jun 26, 2023, 1:50:17 AM6/26/23
to jpat...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to Google Ads API Forum.

You mentioned that it is working on your end via API explorer using the REST API. It seems the issues you encountered are specific to the PHP client library. It seems like your concern is more on the implementation / integration of our client libraries. That said, I would recommend reaching out to the developer who maintains our client libraries PHP (Github Issues) in the link below.

Reference links included in this email:

 

This message is in relation to case "ref:_00D1U1174p._5004Q2mWsZT:ref"

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages