简体   繁体   English

如何获得使用ruby的facebook活动印象和每个活动预算的列表?

[英]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 . 我有以下代码,可以使用facebook-ruby-business-sdk返回我在Facebook业务经理帐户中拥有的所有广告系列的名称列表。

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 . 最后一个循环中的campaign对象是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. 让我知道您的生活状况或有任何疑问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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