Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gem is making more calls than necessary #52

Closed
kurko opened this issue Aug 7, 2018 · 9 comments
Closed

Gem is making more calls than necessary #52

kurko opened this issue Aug 7, 2018 · 9 comments
Labels

Comments

@kurko
Copy link

kurko commented Aug 7, 2018

tl;dr there are 2 problems, Batch doesn't return a response with anything other than ids and the gem makes N requests for N attributes that are called on an object.

Context

I'm creating many AdSets with FacebookAds::Batch.with_batch. When I do batch.execute, I get back only ids:

[
  #<FacebookAds::AdSet {:id=>\"some-id-1\"}>,
  #<FacebookAds::AdSet {:id=>\"some-id-2\"}>,
  #<FacebookAds::AdSet {:id=>\"some-id-3\"}>
]

I need to access its name and status (I want to double check that those were created correctly). When I do object.first.name, it makes Request1:

Request GET https://graph.facebook.com/v3.0/some-id-1?access_token=my-access-token&appsecret_proof=secret-prood&fields=name

Calling object.first.status, another request is made:

Request GET https://graph.facebook.com/v3.0/some-id-1?access_token=my-access-token&appsecret_proof=secret-prood&fields=status

The diff is the fields at the end. That led me to just load those ids with ::FacebookAds::AdSet

The Problem

I want to load those records, so I do the following for each id:

::FacebookAds::AdSet.get('some-id-1', 'name,status,campaign_id', session)

That works, except that in reality I'm creating 3,000 ad sets for N customers. Facebook simply won't accept that many requests in serial. I tried using FacebookAds::Batch.with_batch to no avail.

Questions

  1. Is there a way to create records in a batch and get them back with all their attributes, not just id?
  2. Is there a way to call object.name and have it request N attributes at once, instead of one call per attribute? This is very inconvenient.
  3. Is there a way to load N adsets by ids without making N requests?

Thanks a lot.

@ssankim
Copy link

ssankim commented Aug 10, 2018

Ad Set endpoint support Read-After-Write, so you can use it.

FacebookAds::Batch.with_batch do
  5.times.map do |n|
    ad_account.adsets.create(..., fields: %w[id name status])
  end
end.execute

=> [#<FacebookAds::AdSet {:id=>"...", :name=>"...", :status=>"..."}>,
 #<FacebookAds::AdSet {:id=>"...", :name=>"...", :status=>"..."}>,
 #<FacebookAds::AdSet {:id=>"...", :name=>"...", :status=>"..."}>,
 #<FacebookAds::AdSet {:id=>"...", :name=>"...", :status=>"..."}>,
 #<FacebookAds::AdSet {:id=>"...", :name=>"...", :status=>"..."}>]

It's little bit hacky, but you also possible using Multiple ID Read Requests with this.

ids = [<ADSET_ID>, <ADSET_ID>, ...]

FacebookAds::APIRequest.new(
  :get,
  '',
  params: { ids: ids.join(","), fields: "id,name,status" },
  session: <SESSION>
).execute_now

=> #<FacebookAds::APIResponse:0x00007fd62c2fa008
 @body=<BODY>,
 @headers=<HEADERS>,
 @status_code=<HTTP_STATUS>>

@stale
Copy link

stale bot commented Jan 14, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Jan 14, 2020
@kurko
Copy link
Author

kurko commented Jan 17, 2020

Still waiting for some official answer

@stale stale bot removed the Stale label Jan 17, 2020
@stale
Copy link

stale bot commented Apr 17, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Apr 17, 2020
@kurko
Copy link
Author

kurko commented Apr 17, 2020

Still waiting for some official answer

@stale stale bot removed the Stale label Apr 17, 2020
@stale
Copy link

stale bot commented Jul 18, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Jul 18, 2020
@kurko
Copy link
Author

kurko commented Jul 20, 2020

Still waiting for some official answer

@stale stale bot removed the Stale label Jul 20, 2020
@stale
Copy link

stale bot commented Dec 25, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Dec 25, 2020
@stale
Copy link

stale bot commented Jan 8, 2022

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants