Daniel Bonnell
Daniel Bonnell

Reputation: 4997

Facebook API Check Rate Limit Usage /w Koala Gem

I'm using the Koala gem to connect to the Graph API. What I would like to know is how I can check my API usage against the rate limit using the gem. The gem doesn't seem to expose request headers in a way that would allow me to see if I am approaching my rate limit. I've also checked the API docs and can't find any information on how to check my usage programmatically, such as calling an endpoint to get usage data.

It looks like someone already forked the gem (link to issue report) for this purpose already (link to fork), but they don't provide a working example in code of how to pull the headers from a response and I have been unable to get it working myself.

For example, if I use the Shopify fork and try the following code, it returns an error:

[10] pry(main)> client = current_user.facebook_client
=> #<Koala::Facebook::API:0x007f84f94fbb60
 @access_token="SOMETHING",
 @app_secret="SECRET">
[11] pry(main)> resp = client.search('pokemon', type: :page)
=> [{"name"=>"Pokémon", "id"=>"230809307041021"},
 {"name"=>"Pokemon-Go", "id"=>"661667727331478"},...]
[12] pry(main)> resp.headers
NoMethodError: undefined method `headers' for #<Koala::Facebook::API::GraphCollection:0x007f84fb878ea8>
from (pry):12:in `__pry__'

I've also tried calling client.headers, which returns valid headers data, but the data includes nothing about my usage.

Upvotes: 0

Views: 281

Answers (0)

Related Questions