Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: How do I use curl with perl and Twitter

by Corion (Patriarch)
on Jul 20, 2009 at 19:38 UTC ( #781746=note: print w/replies, xml ) Need Help??

in reply to How do I use curl with perl and Twitter

Why don't you use Net::Twitter, which is a tested and working Perl interface to the Twitter API? The ->show_user() method seems to be applicable.

Replies are listed 'Best First'.
Re^2: How do I use curl with perl and Twitter
by northwestdev (Acolyte) on Jul 21, 2009 at 06:03 UTC
    So, then if I use something like this, it should work?
    my $nt = Net::Twitter->new( traits => [qw/API::REST/], username => $username, password => $pwd, apihost => "/users/show/".$TwitterID.".xml" ); my $result = $nt->show_user;
    The API url defaults to, and I assume that the apihost, would be the remainder of the REST call, and by calling show_user, instead of show_user(id) -- while using an apihost that terminates with .xml, I am guaranteed a response that's an xml string. The documentation was not clear on what format I should expect if I use show_user(id), which would assume the default apihost.

      I'm not sure that what you wrote above would work, because the apihost parameter is, unsurprisingly, documented in the Net::Twitter as:

      A string containing the Twitter API host. It defaults to "". This option is available when the API::REST trait is included.

      I'm not sure where you get the idea that you have to construct any URLs yourself - this is what the module should shield you from. But I'm sure that, instead of theoretical musings, it would be far more productive if you actually tried things out and came back only if you had further questions or error messages to report.

        Actually, you're shielded from the URL only if you use certain methods. show_user is not one of them: you need to specify a user, and a format in the URL. I should be setting apiurl instead of apihost. Confusion resulting from using apihost in PHP with curl. In any case, I figured out why I kept getting error 500. I took out all code, except for a statement to print out Hello World. When I commented out the use Net::Twitter, it printed out fine, and when I put it back in, I got error 500. This happened on a hosting account I have on goDaddy and another I have on a generic Apache Host. So, it seems as if Net::Twitter is not in general use as a Perl module.

      You're making this far harder than it needs to be.

      #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::Twitter; my $nt = Net::Twitter->new; print Dumper $nt->show_user('davorg');

      You don't even need to authenticate unless you're trying to access a user who has protected their updates.


      See the Copyright notice on my home node.

      Perl training courses

        The reason why I need to authenticate, is that Twitter rate limits its non-authenticated API calls to a small number of calls every hour. Authenticated (and pre-authorized) accounts, get a much bigger allowance. I did get Net::Twitter installed, and I'm about to test it.
        FYI: I am a Perl newbie. It is somewhat working, but I cannot figure out why this piece of code is not producing any output:
        my $nt = Net::Twitter->new( traits => [qw/API::REST/], username => $usename, password => $pwd ); my $results = $nt->show_user($twitterID); foreach my $user (@{ $results }) { my $id = $user->{id}; my $name = $user->{name}; print STDOUT $id." ".$name."<br>"; }
        No error messages either. I know it's about the way I am accessing the $user hash. I did some perl reading, and even one of the examples in Net::Twitter uses the same code.
Re^2: How do I use curl with perl and Twitter
by vek (Prior) on Jul 23, 2009 at 21:40 UTC

    Ordinarily I'd agree with you 100%. But playing devil's advocate for a second means I should point out that Net::Twitter requires Moose which requires half the CPAN. So one possible reason why anyone would avoid Net::Twitter is the somewhat lengthy and involved install process.

    But in that case there's Net::Twitter::Lite

    -- vek --
      Net::Twitter requires Moose which requires half the CPAN

      Actually it has only 4 direct (non-core) dependencies, this expands to only 21 dependencies in total (6 of which are core). See here for the actual list of dependencies, and here for a detailed listing and justification for each one.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://781746]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-05-16 21:40 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (63 votes). Check out past polls.