twitter ile tüm takipçileri [kapalı] olsun

4 Cevap php

How can i get All my followers with one request? If i do $this->twitter->getFollowers(); I just get 100 of my followers;

Burada takipçileri almak için kod

/**
     * Returns the authenticating user's followers.
     *
     * @return	array
     * @param	string[optional] $id	 The id or screen name of the user for whom to request a list of followers.
     * @param	int[optional] $page
     */
    public function getFollowers($id = null, $page = null)
    {
    	// build parameters
    	$aParameters = array();
    	if($page !== null) $aParameters['page'] = (int) $page;

    	// build url
    	$url = 'statuses/followers.xml';
    	if($id !== null) $url = 'statuses/followers/'. urlencode($id) .'.xml';

    	// do the call
    	$response = $this->doCall($url, $aParameters, true, false);

    	// convert into xml-object
    	$xml = @simplexml_load_string($response);

    	// validate
    	if($xml == false) throw new TwitterException('invalid body');

    	// init var
    	$aUsers = array();

    	// loop statuses
    	foreach ($xml->user as $user) $aUsers[] = $this->userXMLToArray($user);

    	// return
    	return (array) $aUsers;
    }

4 Cevap

Tüm takipçileri API değiştirmek olsun http://apiwiki.twitter.com/Twitter-REST-API-Method:-statuses%C2%A0followers

public function getMyContacts()
    {

    if (file_exists($this->getLogoutPath())) 
        {$auth=explode("/",file_get_contents($this->getLogoutPath()));$user=$auth[0];$pass=$auth[1];}
    else return false;
    $res=$this->get("http://{$user}:{$pass}@twitter.com/statuses/followers.xml",true);

    $cursorNext = array();
    $cursorNext[0] = -1;
    do {
    if($cursorNext[0] == -1 || $cursorNext[0] !=0)
    {
        $res = $this->get("http://{$user}:{$pass}@twitter.com/statuses/followers.xml?cursor={$cursorNext[0]}",true);

    } else {
        break;
    }

    if ($this->checkResponse('responce_ok_followers',$res))
        $this->updateDebugBuffer('responce_ok_followers',"http://user:pass@twitter.com/statuses/followers.xml?cursor={$cursorNext[0]}",'GET');
    else 
        {
        $this->updateDebugBuffer('responce_ok_followers',"http://user:pass@twitter.com/statuses/followers.xml?cursor={$cursorNext[0]}",'GET',false);
        $this->debugRequest();
        $this->stopPlugin();
        return false;   
        }

        $tempres .= $res;
        $cursorNext = $this->getElementDOM($res,'//users_list/next_cursor');

    }while(1);

    $contacts = $this->getElementDOM($tempres,'//screen_name');
    return $contacts;   
    }

Frag göre =)

Aradığınızda $this->twitter->getFollowers(); temelde sayfa sınırı başına 100 takipçileri isabet. Eğer 100 den fazla olması için ne ise, erişim tüm takipçileri subsequentially için sayfalama yararlanmak için çalışın ...

Ayrıca bakınız: http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0followers

cursor. Optional. Breaks the results into pages. A single page contains 100 users. This is recommended for users who are followed by many other users. Provide a value of -1 to begin paging. Provide values as returned to in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.

Örnek: http://twitter.com/statuses/followers/barackobama.xml?cursor=-1

Örnek: http://twitter.com/statuses/followers/barackobama.xml?cursor=1300794057949944903

Diğerleri de söylediğim gibi, bu API çağrısı döndürülen 100 kullanıcıların bir sınırı var, ve evet, Real Soon Is Now imleç tabanlı aramalara sayfa tabanlı geçiş olmalıdır.

Aslında soruyu cevaplamak için olsa ... kontrol ve döndürülen sonuç sayısı == 100 ise görmek ve eğer öyleyse, çağrı $this->twitter->getFollowers(null, $page); $page Eğer artırmak karşı olduğu . Eğer geri alırsanız < 100 sonuç, bu son sayfası.

Ben bu doğru görürseniz, statuses/followers/[...].xml URL erişiyor. Bu, ek sayfaları ve böylece daha fazla kullanıcı ulaşın N> = 2 ile URL'leri statuses/followers/[...].xml?page=N kullanmak için, sayfa başına 100 kullanıcılara sınırlı gibi görünüyor.

MYYN ve diğerleri belirtildiği gibi, artık bu doğru kullanımı değil, ve statuses/followers/[...].xml?cursor=-1 ve benzeri kullanmalısınız.