Racking my brain to figure out how to use users/show

1 view
Skip to first unread message

krumlr

unread,
Jan 4, 2009, 5:43:49 PM1/4/09
to Twitter Development Talk
I am trying to get the user picture (profile_image_url) from a Twitter
account using either http://twitter.com/users/show/username.xml or
http://twitter.com/users/show/username.json. My problem is that I am a
PHP guy and it seems that I can't load this information via the http
protocol. It would on the surface seem simple enough to do but it is
not working out that way. I may be having a brain-dead-day so I
thought I would ask for any ideas I may be overlooking from this
bright group.

Pete

Waitman Gobble

unread,
Jan 4, 2009, 5:50:30 PM1/4/09
to Twitter Development Talk

hmmm. it's in

profile_image_url

For example,

<h1>Web Girly</h1><p>Chicago, IL</p><p><img src="http://
s3.amazonaws.com/twitter_production/profile_images/14391342/
images_normal.jpg"></p>

whatcha wanna do save the image to the local filesystem?



On Jan 4, 2:43 pm, krumlr <petewing...@gmail.com> wrote:
> I am trying to get the user picture (profile_image_url) from a Twitter
> account using eitherhttp://twitter.com/users/show/username.xmlorhttp://twitter.com/users/show/username.json. My problem is that I am a.

j03

unread,
Jan 5, 2009, 5:43:00 AM1/5/09
to Twitter Development Talk
Are you using Curl or Sockets?

On Jan 4, 10:43 pm, krumlr <petewing...@gmail.com> wrote:
> I am trying to get the user picture (profile_image_url) from a Twitter
> account using eitherhttp://twitter.com/users/show/username.xmlorhttp://twitter.com/users/show/username.json. My problem is that I am a

Pete Wingard

unread,
Jan 5, 2009, 9:31:30 AM1/5/09
to twitter-deve...@googlegroups.com
yes. I want to save the image to my server so my app won't depend on Twitter to provide the picture
--
Pete Wingard

Krumlr.Com
MudSweatAndTears.Com
PixelCast.Net
TigerTailST.Com
& Yougler.Com

you can follow on Twitter
http://www.twitter.com/krumlr

Decatur, GA
404.797.1646
http://yougler.com/pete
netl...@gmail.com

Pete Wingard

unread,
Jan 5, 2009, 9:35:25 AM1/5/09
to twitter-deve...@googlegroups.com
As of now I am using nothing. My existing API calls uses cURL and I have tried to use a several ways to grab and save the image but to no avail. I think it has to with the http: protocol. As a protection my server can't acces another server via http:?

fastest963

unread,
Jan 5, 2009, 10:45:35 AM1/5/09
to Twitter Development Talk
Just use fwrite($local, file_get_contents());
Also, use the JSON format and the json_decode, and it will make a nice
array for you. Then you can use a regex to get the src from the
profile_image_url.

If you wanted I could write some simple code up if you can't
understand what I mean?
As far as a faster/better way to "download" the image, you could try
maybe CURL and then do a fwrite with that, or you could use sockets,
but file_get_contents() is the easiest.

Pete Wingard

unread,
Jan 5, 2009, 11:05:55 AM1/5/09
to twitter-deve...@googlegroups.com
Tyes please show me what you mean. Even though I know what to look for and where to get it and once I get it I can copy it to my database I can't get PHP to download the XML file using http.

Pete Wingard

unread,
Jan 5, 2009, 11:07:36 AM1/5/09
to twitter-deve...@googlegroups.com
Also I am not very familiar with JSON. Thanks

Pete Wingard

unread,
Jan 5, 2009, 1:53:05 PM1/5/09
to twitter-deve...@googlegroups.com
I have this cURL 

       function get_tweets(){
       // create a new cURL resource
       $ch = curl_init();
$user = "netlatch";
       $pass = "************";
       // set URL and other appropriate options
       curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
       curl_setopt($ch, CURLOPT_URL, "http://twitter.com/users/show/netlatch.json");
       curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);

       // grab URL and pass it to the browser
       $input = curl_exec($ch);
       $val = json_decode($input);
       $output = $val->{"text"};
       // close cURL resource, and free up system resources
       curl_close($ch);
       return $output;
}
$array=get_tweets();

but I get nothing in the $array. It dumps the content on the page though. If I use this w/o a username and password I get an error of too many requests. What am I doing wrong? 

Stuart

unread,
Jan 5, 2009, 2:12:42 PM1/5/09
to twitter-deve...@googlegroups.com
Debugging 101...

2009/1/5 Pete Wingard <petew...@gmail.com>:


> I have this cURL
> function get_tweets(){
> // create a new cURL resource
> $ch = curl_init();
> $user = "netlatch";
> $pass = "************";
> // set URL and other appropriate options
> // $user:$pass http://twitter.com/statuses/replies.json
> curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
> curl_setopt($ch, CURLOPT_URL,
> "http://twitter.com/users/show/netlatch.json");
> curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
> // grab URL and pass it to the browser
> $input = curl_exec($ch);

var_dump($input);

> $val = json_decode($input);

var_dump($val);

> $output = $val->{"text"};

var_dump($output);

> // close cURL resource, and free up system resources
> curl_close($ch);
> return $output;
> }
> $array=get_tweets();
> but I get nothing in the $array. It dumps the content on the page though. If
> I use this w/o a username and password I get an error of too many requests.
> What am I doing wrong?

You're not doing basic legwork before asking for help. However, I'm
gonna throw you a bone. Read up on the CURLOPT_RETURNTRANSFER option -
that's what you're missing.

-Stuart

--
http://stut.net/

Peter Denton

unread,
Jan 5, 2009, 2:18:07 PM1/5/09
to twitter-deve...@googlegroups.com
also, you could try with what you have currently, curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

Pete Wingard

unread,
Jan 5, 2009, 2:38:36 PM1/5/09
to twitter-deve...@googlegroups.com
I've been at it for two days. I generally don't ask for much help but based on your response I shouldn't ask for anymore. I suppose no one ever helped you a time or two. Thanks for the bone.

Peter Denton

unread,
Jan 5, 2009, 2:40:34 PM1/5/09
to twitter-deve...@googlegroups.com
Here is what I use. Can you juse use XML?

    $username = 'yourusername';
    $password = 'yourpassword';
   
    $host = "http://twitter.com/users/show/$businessUser.xml";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $host);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
    $result = curl_exec($ch);
    curl_close($ch);
    $xml = new SimpleXMLElement($result);

Chad Etzel

unread,
Jan 5, 2009, 2:46:09 PM1/5/09
to twitter-deve...@googlegroups.com
Woah woah... if no-body ever needed to ask for help, then mailing
lists such as these wouldn't exist at all... I hate to see somebody be
discouraged from strengthening their knowledge of programming, so
please ask away! At worst you'll be flamed, but at best you'll get an
answer that may help you.

Once you get the xml/json thing figured out, you might want to look
into the PHP functions:
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromgif

http://us2.php.net/manual/en/function.imagecreatefromjpeg.php

to help you save the images locally... I've done this before to store
user avatars on my server.

-Chad

Nicole Simon

unread,
Jan 5, 2009, 2:47:52 PM1/5/09
to twitter-deve...@googlegroups.com


On Mon, Jan 5, 2009 at 8:40 PM, Peter Denton <petermdenton

    $host = "http://twitter.com/users/show/$businessUser.xml";

shouldt that be https for more secure transmission of the data`?

Nicole
--

http://twitter.com/NicoleSimon // http://mit140zeichen.de/
http://crueltobekind.org // http://beissholz.de

skype: nicole.simon / mailto:nee...@gmail.com
phone: +49 451 899 75 03 / mobile: +49 179 499 7076


Matthias Bauer

unread,
Jan 5, 2009, 2:43:18 PM1/5/09
to twitter-deve...@googlegroups.com
Pete Wingard wrote:
> I have this cURL
>
> function get_tweets(){
> // create a new cURL resource
> $ch = curl_init();
> $user = "netlatch";
> $pass = "************";
> // set URL and other appropriate options
> // $user:$pass http://twitter.com/statuses/replies.json
> curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
> curl_setopt($ch, CURLOPT_URL,
> "http://twitter.com/users/show/netlatch.json");
> curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
>
> // grab URL and pass it to the browser
> $input = curl_exec($ch);
> $val = json_decode($input);
> $output = $val->{"text"};
> // close cURL resource, and free up system resources
> curl_close($ch);
> return $output;
> }
> $array=get_tweets();
>
> but I get nothing in the $array. It dumps the content on the page
> though. If I use this w/o a username and password I get an error of too
> many requests. What am I doing wrong?

You need to set

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

or $input will contain the curl result code, not the page contents.


-Matt

Matthias Bauer

unread,
Jan 5, 2009, 2:43:18 PM1/5/09
to twitter-deve...@googlegroups.com
Pete Wingard wrote:
> I have this cURL
>
> function get_tweets(){
> // create a new cURL resource
> $ch = curl_init();
> $user = "netlatch";
> $pass = "************";
> // set URL and other appropriate options
> // $user:$pass http://twitter.com/statuses/replies.json
> curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
> curl_setopt($ch, CURLOPT_URL,
> "http://twitter.com/users/show/netlatch.json");
> curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
>
> // grab URL and pass it to the browser
> $input = curl_exec($ch);
> $val = json_decode($input);
> $output = $val->{"text"};
> // close cURL resource, and free up system resources
> curl_close($ch);
> return $output;
> }
> $array=get_tweets();
>
> but I get nothing in the $array. It dumps the content on the page
> though. If I use this w/o a username and password I get an error of too
> many requests. What am I doing wrong?

You need to set

Pete Wingard

unread,
Jan 5, 2009, 3:12:02 PM1/5/09
to twitter-deve...@googlegroups.com
I couldn't get your code to work (simpleXML errors) but this does: Thanks Peter.
$username="netlatch";
$password="**********";
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "http://twitter.com/users/show/$username.json");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, $username.":".$password);
    $result = curl_exec ($curl);
$result = json_decode($result);
    curl_close ($curl);
echo "<pre>";
print_r($result);
echo "</pre>";

Stuart

unread,
Jan 5, 2009, 4:20:16 PM1/5/09
to twitter-deve...@googlegroups.com
2009/1/5 Pete Wingard <petew...@gmail.com>:

> I've been at it for two days. I generally don't ask for much help but based
> on your response I shouldn't ask for anymore. I suppose no one ever helped
> you a time or two. Thanks for the bone.

I apologise if I got the tone of my email wrong, but your problem
indicates to me that you haven't really read the documentation for the
curl extension in the PHP manual. I have no problem helping people who
have done the basics... 1) read the manual, 2) have a go, and 3) apply
basic debugging skills if it doesn't work.

You've demonstrated 2, great, but I saw little to no evidence of 1 and 3.

In response to Chad's email I take the view that fishing is always a
better option than going to a fish market where coding is concerned.

-Stuart

--
http://stut.net/

Chad Etzel

unread,
Jan 5, 2009, 4:28:26 PM1/5/09
to twitter-deve...@googlegroups.com
On Mon, Jan 5, 2009 at 4:20 PM, Stuart <stu...@gmail.com> wrote:
>
>
>
> In response to Chad's email I take the view that fishing is always a
> better option than going to a fish market where coding is concerned.
>

True, and I agree... but sometimes you must go to the fish market
first in order to learn that you should really buy a fishing pole
instead.

In any event, I am grateful that there really isn't a lot of total
n00bage on this list (like on so many other lists). I did not mean to
offend either... just didn't want to Pete to get discouraged since
what he is trying to do is entirely possible.

-Chad

Pete Wingard

unread,
Jan 5, 2009, 4:35:16 PM1/5/09
to twitter-deve...@googlegroups.com
Thanks for the response. Your point was well taken and I was being a bit sensitive to the tone. Sorry bout that.
Reply all
Reply to author
Forward
0 new messages