Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Perl / New Twitter API

by DanielSpaniel (Scribe)
on Jul 02, 2013 at 17:35 UTC ( [id://1042071]=perlquestion: print w/replies, xml ) Need Help??

DanielSpaniel has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Twitter recently updated their API (June 11th, 2013) and, not surprisingly, my code no longer works.

However, I found that, for Perl at least, it seemed an easy enough problem to solve, because a new/updated Perl module was also released to accommodate the new API.

My little test script is below:
#!/usr/bin/perl use strict; use Net::Twitter::Lite::WithAPIv1_1; use Scalar::Util 'blessed'; use Data::Dumper; my $nt=''; my $r=''; eval{ $nt = Net::Twitter::Lite::WithAPIv1_1->new; my $terms='nyc'; # Just a test term $r = $nt->search($terms); }; print Dumper($r); exit;

However, I never seem able to get data back, and the output from Dumper is always: $VAR1 = '', no matter what the search term.

So far as I can see I think I'm doing everything okay (module docs at: http://search.cpan.org/~mmims/Net-Twitter-Lite-0.12004/lib/Net/Twitter/Lite/WithAPIv1_1.pod), and from my perspective there's really not too much difference between using the new module and the old one.

I'm sure that many other people must also have had issues when Twitter updated their API, so I'm hoping maybe somebody can assist.

FYI, for reading tweets from Twitter, no authentication is required.

Any help would be much appreciated.

Replies are listed 'Best First'.
Re: Perl / New Twitter API
by toolic (Bishop) on Jul 02, 2013 at 18:00 UTC
    When I run your code without the eval, I get an error message:
    use warnings; use strict; use Net::Twitter::Lite::WithAPIv1_1; use Scalar::Util 'blessed'; use Data::Dumper; my $nt = Net::Twitter::Lite::WithAPIv1_1->new(); my $terms = 'nyc'; # Just a test term my $r = $nt->search($terms); print Dumper($r); exit; __END__ 400: Bad Request

      Actually, I should have probably tried it without the eval block myself before posting; yes, I too just got the same 400 response.

      Odd. Even so, according to the module doc's the request is set up correctly, and I don't know what else might be wrong.

      I guess it literally is Twitter saying it's a bad request, but if anyone has any experience with the new API then I'd appreciate any thoughts.

      Thanks.

        Well, there's two bits that could be causing problems - Twitter's API, or the module isn't _quite_ right with their new API changes.

        If you're wanting to do something fairly straightforward, can you just hook straight into twitter? https://dev.twitter.com/docs/using-search

        I've just tried clicking through their example URLs, but it hasn't worked. But that might be a reasonable start point - after all, you can then just stick together using 'LWP'. I think that might be because (according to some quick and dirty googling) API 1.1 is now fussier about authentication.

        If you try opening: https://api.twitter.com/1.1/search/tweets.json?q=nyc - do you get a 215 'bad authentication' error like I do?

Re: Perl / New Twitter API
by dmck (Initiate) on Aug 26, 2013 at 17:04 UTC
    26 August: I'm using Net::Twitter::Lite::WithAPIv1_1 (version 0.12004) and I was getting '410 Gone' responses from Twitter. For an app which had worked with Twitter v1 API. I found that if I added
    apiurl => 'http://api.twitter.com/1.1',
    to the call of Net::Twitter::Lite::WithAPIv1_1->new() after my keys and tokens, then it worked.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1042071]
Approved by Lawliet
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found