abraham / twitteroauth

The most popular PHP library for use with the Twitter OAuth REST API.
https://twitteroauth.com
MIT License
4.29k stars 1.71k forks source link

Accessing "x_rate_limit_remaining" value...? #449

Closed mbarwick83 closed 8 years ago

mbarwick83 commented 8 years ago

I can't seem to get this working. I want to check the remaining rate limit value...as below. But I'm getting an error that $headers is a undefined property. Help?

$twitter = new TwitterApi($oauth->oauth_token, $oauth->oauth_token_secret);
$results = $twitter->get("followers/ids", ["user_id" => $page_id, "cursor" => $results->next_cursor]);

if ($twitter->headers["x_rate_limit_remaining"] == 0)
abraham commented 8 years ago

You'll want to use $twitter->getLastXHeaders().

mbarwick83 commented 8 years ago

That get's a list if I var_dump...but I still can't echo out "x_rate_limit_remaining". How would I call rate_limit using getLastXHeaders?

abraham commented 8 years ago

It returns an array so you then access it just like you were initially trying.

$twitter->getLastXHeaders()["x_rate_limit_remaining"]

Note that the response is a string "0" not an integer.

mbarwick83 commented 8 years ago

Hmm, I tried that last night. Let me revisit it with a fresh mind. Thanks for your help. This library is :100: :+1:

adiospeds commented 8 years ago

doesn't work for me as well