facebook / facebook-ruby-business-sdk

Ruby SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
210 stars 160 forks source link

Include Insights calls in Batch? #106

Closed jcat4 closed 4 years ago

jcat4 commented 4 years ago

Which SDK version are you using?

0.7.0.2

What's the issue?

I need to make multiple insights calls to get around Facebook's breakdown permutation limitations, and so I am attempting to nest multiple insights calls for a single ad in a batch call, but I cannot figure out how to get the operations to populate.

Steps/Sample code to reproduce the issue

Note: I'm playing around with 5 of the same insights calls before I actually start any logic breaking out multiple fields. 😁

ad_data = FacebookAds::Ad.get(some_ad_id)

batch = FacebookAds::Batch.with_batch do
  5.times.map do |n|
    ad_data.insights(fields: 'impressions', date_preset: 'last_7d')
  end
end

# It's 0
puts batch.operations.size

# It's [], because operations are empty
results = batch.execute

Observed Results:

batch.operations is empty, and thus batch.execute returns an empty array. 😢

Expected Results:

What I hoped would happen is that the batch object would contain 5 insights operations that would remotely be kicked off once I called batch.execute, but again, batch.operations isn't populating...

My guess from looking at the SDK's source is that I need to be passing an array of FacebookAds::APIRequest instances to the batch block. Looks like insights is just a PORO?

Apologies if this is obvious and I'm just missing something... Can someone help point me in the right direction? Thanks!

jcat4 commented 4 years ago

I've decided on a different approach. I had an idea as to how to do what I wanted, but I don't know if I'd be able to use the actual insights edge to do what I wanted here.

Gonna go ahead and close this since I don't need an answer anymore.