简体   繁体   中英

How does one get a list of facebook campaign impressions and budget per campaign with ruby?

I have the following code that returns a list of names of all campaigns that I have in my Facebook business manager account using facebook-ruby-business-sdk .

require 'facebookbusiness'
FacebookAds.configure do |config|
  config.access_token = '_____private_info______'
  config.app_secret = '_____private_info______'
end

ad_account = FacebookAds::AdAccount.get('act______private_info______', 'name')
puts "Ad Account Name: #{ad_account.name}"

# Printing all campaign names
ad_account.campaigns(fields: 'name').each do |campaign|
  puts campaign.name
end

The campaign object in the final loop is an instance of FacebookAds::Campaign .

Rather than just having a list of names, I also need budget and impressions for each campaign in the last month.

How do I need to change the code to get these results?

It looks to me as if you just need to select the fields and they'll be available in your loop:

ad_account.campaigns(fields: %w[name budget impressions]).each do |campaign|
  puts [campaign.name, campaign.budget, campaign.impressions].join(', ')
end

Does that work for you? Let me know how you get on or if you have any questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM