Using Twitter Access Tokens interchangeably (ie. use 1 user's token for another user)?

twitter

Solution

I've used oAuth Library of abraham (https://github.com/abraham/twitteroauth) in PHP-Zend. I've also stored user's access token in database and I've made below function to get App Rate Limit.

public function getAppLimit($user_id)
    {        

       $data = $this->getTwitterConnection($user_id);

        $connection = new TwitterOAuth(self :: CONSUMER_KEY, self :: CONSUMER_SECRET, $data['oauth_token'], $data['oauth_token_secret']);

        $rate_limit = $connection->get('application/rate_limit_status');

        return $rate_limit;        
    }

Now you get all API rate limits. you want for search it will give below data

["search"] => object(stdClass)#170 (1) {
      ["/search/tweets"] => object(stdClass)#171 (3) {
        ["limit"] => int(180)
        ["remaining"] => int(180)
        ["reset"] => int(1366107386)
      }
    }

Now for e.g if user1 limit is exceed than you may use user 2 or user 3 access token but before that you can check user 2 or user 3 rate limit. Now you can see in above search result you will get ['reset'] value. it means it will be reset after that much of time. When user1 limit exceed you need to save that reset parameter and than use user2 and user3 access token for that period of time. And when that 15 mins is over you can again use user 1 access token. And may be if both user2 and user 3 is using that search api on that time window, you may give warning to user 1 that you can do search after some time.

Hope it helps

Problem

Suppose I have 2 Twitter access tokens for user1 and user2. Each has 180 calls to get the tweets for a particular search. Suppose user1 uses all 180 calls in the 15-minute window, is it possible for my app to use the access token for user2 so user1 can make additional calls? This is of course assuming user2 is NOT using his/her access tokens at that moment in time.

Original source