如何从Ruby on Rails中使用Google Adwords流量估算工具获取每次点击费用

时间:2013-07-03 16:25:40

标签: ruby-on-rails google-adwords

我一直在倾向于谷歌adwords api文档,我无法弄清楚如何格式化选择器来检索CPC信息。我正在使用google-adwords-api gem。以下是我在Adwords api模块中使用的方法。

def self.traffic_estimator_service keyword

    if !@adwords #If not already authenticated, do it first
        Adwords.authenticate()
    end

    traffic_estimator_service = @adwords.service(:TrafficEstimatorService, API_VERSION)


    selector = {
        :xsi_type => 'KeywordEstimateRequest',
        :match_type => 'EXACT',
        :keyword => keyword
    }

    data = traffic_estimator_service.get(selector)


    puts '---------------------------------'
    puts data.inspect
    puts '---------------------------------'

end

当然,由于api错误,我从未到过data2.inspect行。即:

AdsCommon::Errors::UnexpectedParametersError (AdsCommon::Errors::UnexpectedParametersError: [:match_type]):

我已经移动了东西并在选择器哈希中尝试了多个东西。有人能给我一个这个选择器哈希应该是什么样子的例子吗?

1 个答案:

答案 0 :(得分:0)

selector = {
  :campaign_estimate_requests => [
    {
      :xsi_type => 'CampaignEstimateRequest',
      :ad_group_estimate_requests =>        {
        :xsi_type => 'AdGroupEstimateRequest',
        :keyword_estimate_requests => [
          {
            :max_cpc => {
              :xsi_type => 'Money',
              :micro_amount => 1_000_000
            },
            :xsi_type => 'KeywordEstimateRequest',
            :keyword => {
              :xsi_type => 'Keyword',
              :text => keyword,
              :match_type => 'EXACT'
            }
          }
        ]
      }
    }
  ]
}