Twitter API: Get Followers +99

前端 未结 7 732
悲&欢浪女
悲&欢浪女 2021-02-06 08:05

Using the twitter API (and OAuth) if i was to call for the user followers, (statuses/followers) i would be returned only 99 results.

Is there a way i can return 99, then

相关标签:
7条回答
  • 2021-02-06 08:30

    Twitter API restricts us to make api Call for method followers/ids is 15 requests per 15 minutes. If you make more than this api will give you an error message that Rate Limit Reached.

    For more information of twitter API rate Limit Visit-https://dev.twitter.com/docs/rate-limiting/1.1 and https://dev.twitter.com/docs/rate-limiting/1.1/limits

    0 讨论(0)
  • 2021-02-06 08:35

    Twitter only allows a certain number of API requests per hour, and I think minute. You might not be able to retrieve any more than 99 requests at once.

    0 讨论(0)
  • 2021-02-06 08:48

    Be sure you're using the right call. followers/ids gives you 5000 at a time (but it's just a list of ids). This call, too, uses the cursor to let you step through pages of users. You get a zero back when you have them all.

    0 讨论(0)
  • 2021-02-06 08:48
    $cursor = -1;
    $account_from = 'twitter_account';
    do
    {
        $json = file_get_contents('http://api.twitter.com/1/statuses/followers/' . $account_from .'json?cursor=' . $cursor);
        $accounts = json_decode($json);
        foreach ($accounts->users as $account)
        {
    
                array(
                    ':twitter_id' => $account->id_str,
                    ':account' => $account->screen_name,
                    ':description' => $account->description,
                );
        }
        $cursor = $accounts->next_cursor;
    
    }
    while ($cursor > 0);
    
    0 讨论(0)
  • 2021-02-06 08:49

    Though I asked this quite a while ago, I came back to building something quite similar recently (+ new programming skills).

    I noticed Twitter API have a method to get all of a users followers (or followings) user ID's in one request. I found the best way was to array_chunk up the ID's into batches of 100 (and only take the first 30 arrays as I dont want to use all the users api requests that hour - they might want to actually tweet!). Then there is a method that allows you to get up to 100 users userinfo (from the view of the currently authenticated user) so I just do a loop (sleep a bit inbetween) and then you've got 30,000 twitter followers!

    I would recommend doing this asynchronously in a queue system, as if you do this on the fly when the users requests a page on the site it could be very slow and you might be prone to a HTTP timeout. Also cache them like hell!

    Sorry I didn't post any code, but hopefully this thought process will help someone :)

    0 讨论(0)
  • 2021-02-06 08:52

    You need to specify cursor parameter as described in the API documrnation. E.g. specify cursor=-1 to request the first page and then use a next_cursor value returned in the first response:

      http://twitter.com/statuses/followers/barackobama.xml?cursor=-1
      http://twitter.com/statuses/followers/barackobama.xml?cursor=1300794057949944903
    
    0 讨论(0)
提交回复
热议问题