jacquagnui / php-twitter

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

showUser will fail for anything other than id #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Request data for a user by specifying username:
$t = new Twitter;
$t->showUser(1, false, false, '2995');

What is the expected output? What do you see instead?
Result will be empty (404).  Expecting user data result.

The problem seems to be with the different url format for calls by id...or
anything other than id.  This fix worked for me:

function showUser( $id, $email = false, $user_id = false, $screen_name=false )
{

    if( !in_array( $this->type, array( 'xml','json' ) ) )
        return false;

    if( $user_id ) :
        $qs = '.' . $this->type . '?user_id=' . (int) $user_id;
    elseif ( $screen_name ) :
        $qs = '.' . $this->type . '?screen_name=' . (string) $screen_name;
    elseif ( $email ) :
        $qs = '.' . $this->type . '?email=' . (string) $email;
    else :
        $qs = (int) $id . '.' . $this->type;
    endif;

      $request = 'http://twitter.com/users/show' . $qs;

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

Original issue reported on code.google.com by garyl...@gmail.com on 10 Apr 2009 at 3:10

GoogleCodeExporter commented 8 years ago
Yeah, I found this problem too. The code above is missing a slash "/" in the 
URL and
has an extra echo statement. I also removed the (int) before $id, so that you 
can
send $t->showUser('username'). Here's the version that I have working:

   function showUser( $id, $email = false, $user_id = false, $screen_name=false )
    {
      if( !in_array( $this->type, array( 'xml','json' ) ) )
          return false;

      if( $user_id ) :
          $qs = '.' . $this->type . '?user_id=' . (int) $user_id;
      elseif ( $screen_name ) :
          $qs = '.' . $this->type . '?screen_name=' . (string) $screen_name;
      elseif ( $email ) :
          $qs = '.' . $this->type . '?email=' . (string) $email;
      else :
          $qs = $id . '.' . $this->type;
      endif;

      $request = 'http://twitter.com/users/show/' . $qs;

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

Original comment by JeffOr...@gmail.com on 18 Apr 2009 at 8:59

GoogleCodeExporter commented 8 years ago
Yup, you're absolutely right about the extra echo.  However, I think we're both 
wrong
with the slash...since the correct formats are:

http://twitter.com/users/show.json?user_id=101010
http://twitter.com/users/show.json?screen_name=john_doe
http://twitter.com/users/show.json?screen_name=johndoe@example.com
http://twitter.com/users/show/101010.json
http://twitter.com/users/show/john_doe.json

Here's an alternate:

   function showUser( $id, $email = false, $user_id = false, $screen_name=false )
    {
      if( !in_array( $this->type, array( 'xml','json' ) ) )
          return false;

      if( $user_id ) :
          $qs = '.' . $this->type . '?user_id=' . (int) $user_id;
      elseif ( $screen_name ) :
          $qs = '.' . $this->type . '?screen_name=' . (string) $screen_name;
      elseif ( $email ) :
          $qs = '.' . $this->type . '?email=' . (string) $email;
      else :
          $qs = '/' . $id . '.' . $this->type;
      endif;

      $request = 'http://twitter.com/users/show' . $qs;

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

Original comment by garyl...@gmail.com on 18 Apr 2009 at 10:25

GoogleCodeExporter commented 8 years ago
Please provide actual patches/diffs in the future. It will help me get code 
into SVN quicker without having to 
ascertain the actual changes. r96 fixes in /branches/1.1 and r95 fixes in 
trunk. Thanks

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

GoogleCodeExporter commented 8 years ago

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