Issues

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

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.


$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

Attached {{Twitter.php.diff}} patch to {{userFriends()}}

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());
}

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

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