Skip to content

Instantly share code, notes, and snippets.

@yappo
Created August 28, 2012 09:25
Show Gist options
  • Save yappo/3496510 to your computer and use it in GitHub Desktop.
Save yappo/3496510 to your computer and use it in GitHub Desktop.
photo_tweet.pl
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