Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created June 11, 2011 07:23
Show Gist options
  • Save ishiduca/1020337 to your computer and use it in GitHub Desktop.
Save ishiduca/1020337 to your computer and use it in GitHub Desktop.
Basic Auth形式でFriendfeedにメッセージを送る
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Encode;
use MIME::Base64;
use LWP::UserAgent;
my $message = "カリー化してみたよ。";
my $username = 'your username';
my $remotekey = 'your remotekey';
my $post = conf_set($username, $remote_key);
my $res = $post->(Encode::encode('utf8', $message));
# with pictures & link
# my $res = $post->(Encode::encode('utf8', $message), {
# files => [ "path/to/file.jpg", ... ],
# link => "http://...",
# });
print $res->status_line , "\n", $res->decoded_content;
exit 0;
sub conf_set {
my($username, $remotekey) = @_;
die qq(! failed: "username" not found.) unless $username;
die qq(! failed: "remotekey" not found.) unless $remotekey;
my $api = 'http://friendfeed-api.com/v2/entry';
my $ua = LWP::UserAgent->new;
my $auth = MIME::Base64::encode(join ':', $username, $remotekey);
$ua->default_header( Authorization => "Basic $auth");
return sub {
no warnings;
my $message = shift;
my $content = shift || {};
if ($content->{file}) {
local $HTTP::Request::Common::DYNAMIC_FILE_UPDATE = 1;
}
$content->{body} = $message;
my $res = $ua->post($api,
Content_type => $content->{file}
? 'form-data'
: 'application/x-www-form-urlencoded',
Content => $content,
);
die qq(! failed: "). $res->status_line . qq(".) unless $res->is_success;
$res;
};
}
__END__
Friendfeedにメッセージを送る関数
See ALSO: http://friendfeed.com/api/documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment