ruby-on-rails Google Ads API Ruby客户端库出现UNEXPECTED_END_OF_QUERY错误

mhd8tkvw  于 2023-04-08  发布在  Ruby
关注(0)|答案(1)|浏览(130)

所以我使用Ruby客户端库。gem 'google-ads-googleads'的版本是21.0.0,Google Ads API版本是13。在使用凭据初始化客户端后,我尝试查询Google Ads Get Account Hierarchy端点之一,我得到错误消息:
<Google::Ads::GoogleAds::V13::Errors::GoogleAdsFailure: errors: [<Google::Ads::GoogleAds::V13::Errors::GoogleAdsError: error_code: <Google::Ads::GoogleAds::V13::Errors::ErrorCode: query_error: :UNEXPECTED_END_OF_QUERY>, message: "Error in query: unexpected end of query.">], request_id: "koqtfsaS6CTB0FxlCHucKg">

client = Google::Ads::GoogleAds::GoogleAdsClient.new do |config|
      config.client_id = client_id
      config.client_secret = client_secret
      config.refresh_token = access_token
      config.developer_token = developer_token
end
google_ads_service = client.service.google_ads
query = <<~QUERY
      SELECT
        customer_client.client_customer,
        customer_client.level,
        customer_client.manager,
        customer_client.descriptive_name,
        customer_client.currency_code,
        customer_client.time_zone,
        customer_client.id
      FROM customer_client
      WHERE customer_client.level <= 1
    QUERY
begin
   request = google_ads_service.search_stream do |search|
        search.customer_id = '8148704352'
        search.query = query
        search.page_size = 100
    end
    request.each do |response|                   
       response.results.each do |row|
           puts row
       end
    end
rescue Google::Ads::GoogleAds::Errors::GoogleAdsError => e
    puts "Error message: #{e.failure}"
end

我尽力了

query = <<~SQL
  SELECT
    customer_client.client_customer,
    customer_client.level,
    customer_client.manager,
    customer_client.descriptive_name,
    customer_client.currency_code,
    customer_client.time_zone,
    customer_client.id
  FROM customer_client
  WHERE customer_client.level <= 1
SQL

我也试过用单引号括起查询,比如query_with_single_quotes ='''+ query +''',但错误并没有消失。

4nkexdtk

4nkexdtk1#

尝试使用SQL.squish而不是query:

query = <<~SQL.squish
  SELECT
    customer_client.client_customer,
    customer_client.level,
    customer_client.manager,
    customer_client.descriptive_name,
    customer_client.currency_code,
    customer_client.time_zone,
    customer_client.id
  FROM customer_client
  WHERE customer_client.level <= 1
SQL

顺便说一下,这个项目有活动记录吗?如果有,你可以这样写:

CustomerClient.where('level <= 1')
              .pluck(:id, :client_customer, :level, :manager,
                     :descriptive_name, :currency_code, :time_zone)

相关问题