facebook / facebook-ruby-business-sdk

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

Unable to get `total_count` from API request #158

Open scottgratton opened 3 years ago

scottgratton commented 3 years ago

Which SDK version are you using?

gem version 0.11.0.0 with api version v11.0

What's the issue?

Unable to retrieve the total_count from the request summary.

Steps/Sample code to reproduce the issue

If I make a request for the campaigns in an ad_account with summary: 'total_count', I see the total account getting logged by the Faraday Request, but I'm unable to retrieve that value. I want a count of all the campaign in an account to monitor how close we are to rate limits without having to first go through every page of campaigns and then count them in memory.

session = FacebookAds::Session.new(access_token: TOKEN)
ad_account = FacebookAds::AdAccount.get("act_#{ACCOUNT_ID}", session)
campaigns = ad_account.campaigns(summary: 'total_count')
campaigns.first

When I make this request, the logger shows the result of the API request along with this total_count that I'm looking for, but I'm unable to actually get this value from the return.

"summary":{"total_count":5012}}

Observed Results:

If you do call count or length on result, you just get the amount that has been added to @collection-- in the case of my example, it's just the first page, and thus returns 10.

Expected Results:

I would expect to be able to get this value of total_count back without having to go through every page. The data is there! What I might expect would be to be able to call total_count on my campaigns object and it would make the api call with summary: 'total_count' and then give me back that value.