google-api-ruby-client
google-api-ruby-client copied to clipboard
Adsense generate_account_report_csv returns nil due to content_type
In Google::Apis::Core::ApiCommand#decode_response_body it checks to see if the content_type starts with JSON_CONTENT_TYPE. The content type comes back as text/csv so it has an explicit return of nil.
def decode_response_body(content_type, body)
return super unless response_representation
return super if options && options.skip_deserialization
return super if content_type.nil?
# HERE content_type = "text/csv" when making a generate_account_report_csv request so it returns nil
return nil unless content_type.start_with?(JSON_CONTENT_TYPE)
body = "{}" if body.empty?
instance = response_class.new
response_representation.new(instance).from_json(body, unwrap: response_class)
instance
end
Environment details
- OS: Ubuntu 20.04
- Ruby version: 3.2.2
- Gem name and version: google-apis-adsense_v2 / 0.31.0
Steps to reproduce
Make a call to generate_account_report_csv
Code example
sense = Google::Apis::AdsenseV2::AdsenseService.new
scope = ['https://www.googleapis.com/auth/adsense']
sense.authorization = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('./account.json'),
scope: scope
)
account = "accounts/pub-xxxxxxxxxxxxx"
result = sense.generate_account_report_csv(
account,
date_range: 'YESTERDAY',
dimensions: %w[DATE],
metrics: %w[PAGE_VIEWS IMPRESSIONS CLICKS]
)
pp result # will be nil