Reputation: 592
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?
Upvotes: 0
Views: 68
Reputation: 12203
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.
Upvotes: 1