Adding followers to a user one at a time is sometimes a VERY lengthy process. Last night the question was posed to me if there was a way to automate adding followers from users who follow someone else.Example scenario:
John Doe follows Jane Doe
John Doe wants to follow at 600 followers of Jane DoeUnfortunately, the Zend_Service_Twitter class doesn't offer any functionality to retrieve a list of followers from another user, but I was able to extend the class and add the functionality. The particular user that I chose to test has roughly 6,000 users. My client didn't want all 6,000, but the first 200. Within 10 minutes the new custom class was written, the script ran, and now my client was now following 200 new people of like mind. :) I plan on submitting the feature request to the Zend Framework gurus to have the ability to find followers from other users so that it can be apart of the main service.Until then here is the class and script: require_once 'Zend/Service/Twitter.php'; class CW_Twitter extends Zend_Service_Twitter { public function __construct($username, $password) {
parent::__construct($username, $password);
} public function getOtherUserFriends($name) {
$this->_init();
$path = '/followers/ids/' . $name . '.json';
$response = $this->restGet($path);
return $response->getBody();
} } $twitter = new CW_Twitter('username', 'password');
$response = $twitter->getOtherUserFriends('friendusername'); $arrayObject = new ArrayObject(Zend_Json::decode($response));
$limitIterator = new LimitIterator($arrayObject->getIterator(), 0, 200); foreach ($limitIterator as $value):
$twitter->friendship->create($limitIterator->current());
endforeach;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment