Created
August 28, 2012 09:25
-
-
Save yappo/3496510 to your computer and use it in GitHub Desktop.
photo_tweet.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use utf8; | |
use 5.017; | |
use Config::Pit; | |
use Encode; | |
use Net::Twitter::Lite; | |
binmode STDOUT => 'utf8'; | |
my($message, $file) = (decode(utf8 => $ARGV[0]), $ARGV[1]); | |
my $config = pit_get('Net::Twitter::Lite-image-upload', require => { | |
consumer_key => 'consumer_key', | |
consumer_secret => 'consumer_secrt', | |
token => 'token', | |
token_secret => 'token_secret', | |
}); | |
my $twitterw = Net::Twitter::Lite->new( | |
legacy_lists_api => 0, | |
ssl => 1, | |
upload_url => 'https://upload.twitter.com/1', | |
%{ $config } | |
); | |
$twitterw->access_token($config->{token}); | |
$twitterw->access_token_secret($config->{token_secret}); | |
my($filename) = $file =~ m{/([^/]+)$}; | |
say "tweet: $message $file"; | |
update_with_media($message, $file, $filename, '35.6184057279992', '139.727510749509'); | |
sub update_with_media { | |
my($msg, $file, $filename, $lat, $lng) = @_; | |
my $content = do { | |
open my $fh, '<:bytes', $file or die "$!: $file"; | |
local $/; | |
<$fh>; | |
}; | |
$twitterw->update_with_media( | |
encode(utf8 => $msg), | |
[ undef, $filename, Content_Type => 'image/jpeg', Content => $content ], | |
{ | |
display_coorrdinates => 'true', | |
lat => $lat, | |
long => $lng, | |
}, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment