Issues

ZF-9215: Zend_Service_Twitter::userFriends() uses deprecated pagination parameter

Issue Type: Bug Created: 2010-02-19T15:16:19.000+0000 Last Updated: 2011-06-14T23:38:48.000+0000 Status: Open Fix version(s): Reporter: Matthew Turland (elazar) Assignee: Pádraic Brady (padraic) Tags: - Zend_Service_Twitter

Related issues: Attachments: - Twitter.php.diff

Description

The userFriends() method of the Zend_Service_Twitter class accepts an array of options as its only parameter. The 'page' parameter is included in the request made to the Twitter API. As of the date of this issue being filed, this parameter is deprecated. According to the documentation for the API method statuses/friends, 'cursor' is the current preferred pagination parameter. (Yes, it's inconsistent with the parameter of the same nature in other methods, such as statuses/friends_timeline.)

A patch to userFriends() is required to properly paginate results from this method, which has been attached to this issue. Additionally, the documentation for Zend_Service_Twitter should be updated to reflect the different usage of the current parameter versus the deprecated one. An example of this is shown below.

<pre class="highlight">
$twitter = new Zend_Service_Twitter('username', 'password');
$cursor = -1; 
do {
    $response = $twitter->user->friends(array('cursor' => $cursor));
    $cursor = (int) $response->next_cursor;
} while (count($response->user) == 100);

Comments

Posted by Matthew Turland (elazar) on 2010-02-19T15:16:56.000+0000

Attached Twitter.php.diff patch to userFriends()

Posted by Tom Shaw (tomshaw) on 2010-06-19T09:42:00.000+0000

I've got both the friends and follower methods to work by removing the integer cast. Twitter is using an eighteen or nineteen digit cursor number.

/**
 * User friends
 *
 * @param  int|string $id Id or username of user for whom to fetch friends
 * @throws Zend_Http_Client_Exception if HTTP request fails or times out
 * @return Zend_Rest_Client_Result
 */
public function userFriends(array $params = array())
{
    $this->_init();
    $path = '/statuses/friends';
    $_params = array();

    foreach ($params as $key => $value) {
        switch (strtolower($key)) {
            case 'id':
                $path .= '/' . $value;
                break;
            case 'cursor':
                $_params['cursor'] = $value;
                break;
            default:
                break;
        }
    }
    $path .= '.xml';
    $response = $this->_get($path, $_params);
    return new Zend_Rest_Client_Result($response->getBody());
}

/**
 * User followers
 *
 * @param  int|string $id Id or username of user for whom to fetch followers
 * @throws Zend_Http_Client_Exception if HTTP request fails or times out
 * @return Zend_Rest_Client_Result
 */
public function userFollowers(array $params = array())
{
    $this->_init();
    $path = '/statuses/followers';
    $_params = array();

    foreach ($params as $key => $value) {
        switch (strtolower($key)) {
            case 'id':
                $path .= '/' . $value;
                break;
            case 'cursor':
                $_params['cursor'] = $value;
                break;
            default:
                break;
        }
    }
    $path .= '.xml';
    $response = $this->_get($path, $_params);
    return new Zend_Rest_Client_Result($response->getBody());
}

Posted by Thorsten Suckow-Homberg (thorsten_suckow) on 2011-05-12T19:33:53.000+0000

Yap, needs a fix. Noone taking care of the Twitter API anymore?

Posted by Jean-Christophe Meillaud (jc.meillaud) on 2011-06-14T23:38:48.000+0000

The fix is not that hard to add, what happens ?

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts