Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # New Version of "Get my latest 7 tweets"
- # Switched to new Twitter API v. 1.1 (2013)
- # This replaces my former version http://pastebin.com/8U3MuTcX
- # Since the XML output format has been erased by Twitter,
- # everything is done with JSON now.
- # The execution time of the script is extremely slow: 1 second
- # => Serverside buffering will be provided (not contained in this code).
- use strict;
- use warnings;
- use Net::Twitter;
- use JSON;
- use CGI::Carp qw(fatalsToBrowser);
- use Encode;
- my $MAX_AGE_IN_SECS = 300;
- my $NUMBER_OF_TWEETS = 7;
- # --- Output result
- print "Content-Type: application/json; charset=utf-8\n";
- print "Cache-Control: max-age=$MAX_AGE_IN_SECS\n";
- print "\n";
- my $nt = Net::Twitter->new(
- traits => [ qw/API::RESTv1_1/ ],
- consumer_key => '<CONSUMER_KEY>',
- consumer_secret => '<CONSUMER_SECRET>',
- access_token => '<ACCESS_TOKEN>',
- access_token_secret => '<ACCESS_TOKEN_SECRET>'
- );
- my $t = $nt->user_timeline({
- count => $NUMBER_OF_TWEETS,
- include_entities => 0,
- contributor_details => 0,
- include_rts => 1,
- truncated => 0,
- });
- my (@tweets, $rt, $text);
- for my $status (@$t) {
- $rt = $status->{retweeted_status};
- if ($rt) { $text = 'RT @'.$rt->{user}->{screen_name}.' '.$rt->{text}; }
- else { $text = $status->{text}; }
- push( @tweets,
- [ "".$status->{id},
- $status->{created_at},
- $text
- ] );
- }
- print encode_json( \@tweets ) . "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement