SalmanAzmat / php-twitter

Automatically exported from code.google.com/p/php-twitter
0 stars 0 forks source link

function friendsTimeline() does not match API #31

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. check notes for r86
2. check class.twitter.php @function friendsTimeline
3. compare and contrast

What is the expected output? What do you see instead?

 * expected: a signature similar to current API, i.e. (since_id, max_id, count, page) and a request 
for the 20 most recent statuses from the user and the user's friends

* instead: return $this->userTimeline(), i.e. the function calls the 
userTimeline function, and 
ignores the actual request.

What version of the product are you using? On what operating system?

* php-twitter-1.1.zip downloaded 2009-05-07 running on OS X (but this is an 
observation of 
the code, the release notes and the current state of the API rather than a 
defect)

Please provide any additional information below.

I am prone to long days and nights of not enough sleep, replacing nutritional 
meals with beer 
and chocolate, and I am by no means an expert (thus could be entirely offbeat).

Original issue reported on code.google.com by three.e...@gmail.com on 7 May 2009 at 8:30

GoogleCodeExporter commented 8 years ago
So according to today's API documentation, it could look like this?

    /**
     * Returns the 20 most recent statuses posted by the authenticating user and that user's friends. This is the equivalent of /timeline/home on the Web.
     * @param boolean|integer $id Specifies the ID or screen name of the user for whom to return the friends_timeline. (set to false if you want to use 
authenticated user).
     * @param $since_id.  Optional.  Returns only statuses with an ID greater than (that is, more recent than) the specified ID. 
     * @param $max_id. Optional.  Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
     * @param $count.  Optional.  Specifies the number of statuses to retrieve. May not be greater than 200. 
     * @param $page. Optional. Specifies the page of results to retrieve. Note: there are pagination limits.
     * @return string
     */
    function friendsTimeline( $id = false, $since_id = false, $max_id = false, $count = false, $page = false )
    {
        if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
            return false;

        $args = array();
        if( $id )
            $args['id'] = $id;
        if( $since_id )
            $args['since_id'] = (int) $since_id;
        if( $max_id )
            $args['max_id'] = (int) $max_id;
        if( $count )
            $args['count'] = (int) $count;
        if( $page )
            $args['page'] = (int) $page;

        $qs = '';
        if( !empty( $args ) )
            $qs = $this->_glue( $args );

        if( $id === false )
            $request = 'http://twitter.com/statuses/friends_timeline.' . $this->type . $qs;
        else
            $request = 'http://twitter.com/statuses/friends_timeline/' . rawurlencode($id) . '.' . $this->type . $qs;

        return $this->objectify( $this->process($request) );
    }

Original comment by three.e...@gmail.com on 7 May 2009 at 1:54

GoogleCodeExporter commented 8 years ago
i agree I am getting exactly the same behavior... the call doesnt return your 
and
your friends timeline, it returns just your replies?!?!

Original comment by mail...@gmail.com on 11 Jun 2009 at 6:00

GoogleCodeExporter commented 8 years ago
If you look at the code, the friendsTimeline() function calls the 
userTimeline() function, and returns the status 
updates for the authenticating user (note, not the authenticating user's 
replies). 

The situation is that the function is simply out of date with the current API. 
If you drop in the code I suggested 
above (which is based on the current API), you will indeed get the friends 
timeline. 

I'm sure the guys will update this in their next release ;)

Original comment by three.e...@gmail.com on 11 Jun 2009 at 6:31

GoogleCodeExporter commented 8 years ago
that is truly awesome and helpful... I should have read the source code, but as 
a bit
of a noob I was a little afraid to look =)

many blessings to you.

@Mikojava

Original comment by mail...@gmail.com on 12 Jun 2009 at 3:05

GoogleCodeExporter commented 8 years ago
Fixes get implemented quicker when actual patch or diff files are provided. 
Means I don't have to ferret out what 
you guys are proposing. And as you know, I don't update all that often because 
I have actual work to do. So 
anything you guys can do to help me get changes in quickly is welcome.

[r93] fixes branches/1.1 and [r94] fixes trunk. Thanks three.easy.

Original comment by emmenset...@gmail.com on 16 Jun 2009 at 5:49

GoogleCodeExporter commented 8 years ago

Original comment by emmenset...@gmail.com on 16 Jun 2009 at 5:50

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thanks for friendsTimeline. 
But I found a little bug in it.

Typecasting variables 'since_id' and 'max_id' to int does not work correctly on 
my 
32bit windows XP box. 
( PHP 5.2.9 (cli) (built: Feb 25 2009 15:52:24) )
It has something to do with int size.

At the time of writing max tweet_id as returned from tweeter is

4438882354

and when I cast this value to int i get

2147483647

this is a code to test this:
<?php

$sinceId='4438882354';

echo "sinceId=" . strval($sinceId) . "\n";

echo "int=" . (int)$sinceId . "\n";
echo "double=" . (double)$sinceId . "\n";
echo "regexp=" . preg_replace('/[^0-9]*/', '', $sinceId) . "\n";

?>

Output:

sinceId=4438882354
int=2147483647
double=4438882354
regexp=4438882354

So, I propose to use casting to double for $since_id and $max_id as a quick fix
(or even better removing all non-numeric characters from $since_id or $max_id 
variablas)
to insure correct arguments in the request.

Instead of:

if( $since_id )
  $args['since_id'] = (int) $since_id;
if( $max_id )
  $args['max_id'] = (int) $max_id;

It should be

if( $since_id )
  $args['since_id'] = (double) $since_id;
if( $max_id )
  $args['max_id'] = (double) $max_id;

Or

if( $since_id )
  $args['since_id'] = preg_replace('/[^0-9]*/', '', $since_id);

if( $max_id )
  $args['max_id'] = preg_replace('/[^0-9]*/', '', $max_id); 

Cheers,
Damir

Original comment by damir.ri...@gmail.com on 28 Sep 2009 at 9:50