2009-11-23 141 views
2

我真的不知道如何在Twitter的API中使用Curesor參數,例如 - here。 我應該爲每100個關注者創建一個新的API調用嗎?瞭解Twitter API的「光標」參數

我喜歡它,如果有人可以提供獲得追隨者的完整列表,假設我有100多家PHP的例子...

提前感謝!

回答

2

您需要將光標值傳遞迴API以獲取下一個「塊」的關注者。然後,您從該塊取出遊標參數並將其傳回以獲取下一個塊。這就像是「獲得下一頁」機制。

0

退房http://code.google.com/p/twitter-boot/source/browse/trunk/twitter-bot.php

foreach ($this->twitter->getFollowers(,0) as $follower)//the 0 is the page 
    { 
     if ($this->twitter->existsFriendship($this->user, $follower['screen_name'])) //If You Follow this user 
      continue; //no need to follow now; 
     try 
     { 
     $this->twitter->createFriendship($follower['screen_name'], true); // If you dont Follow Followit now 
     $this->logger->debug('Following new follower: '.$follower['screen_name']); 
     } 
     catch (Exception $e) 
     { 
     $this->logger->debug("Skipping:".$follower['screen_name']." ".$e->getMessage()); 
     } 

    } 

    } 
+0

這個代碼是關於建立友誼不是檢索跟隨列出 – 2009-11-23 21:20:08

+0

讀碼$這個 - > twitter-> getFollowers()將返回一個數組, 上面就是一個例子你可以用數組 – streetparade 2009-11-23 21:27:56

+0

做,那麼你需要此文件中的定義: http://code.google.com/p/twitter-boot/source/browse/trunk/inc/twitter.php – 2009-11-23 21:38:53

0

因爲這個問題被問,Twitter的API已經在許多方面改變。

光標用於爲許多結果分類API響應。例如,獲取關注者的單個API調用將檢索最多5000個ID。

如果您想要獲得用戶的所有追隨者,您將不得不進行新的API調用,但是這次您必須指出第一個響應中的「next_cursor」編號。

如果有用,以下python代碼將從給定用戶檢索關注者。

它將檢索由常量指示的最大頁數。

要小心,不要被禁止(即:不要讓超過150個的API調用/在匿名電話小時),儘管你問它前一段時間

import requests 
import json 
import sys 


screen_name = sys.argv[1] 
max_pages = 5 
next_cursor = -1 

followers_ids = [] 

for i in range(0,max_pages): 
    url = 'https://api.twitter.com/1/followers/ids.json?screen_name=%s&cursor=%s' % (screen_name, next_cursor) 
    content = requests.get(url).content 
    data = json.loads(content) 
    next_cursor = data['next_cursor'] 

    followers_ids.extend(data['ids']) 

print "%s have %s followers!" % (screen_name, str(len(followers_ids))) 
1

,我希望這將是更積極回答。

  1. Twitter不提供有關next_cursor的含義的信息。只有how cursor works
  2. 這只是Twitter管理分頁的一個簡單方法。
  3. «該功能的目的是線性使用,一個光標定在每個用戶的時間。»Source

«這是潛在的低效率的你,但我們更有效 。»Twitter Staff

但是...以前 有人問斷開的鏈接«是遊標persistents?似乎答案是「是」»

這意味着您可以將最後一個光標保存在0之前並在下次繼續。