[MIXI] mixiAPIについて
リンク
写真付き日記Perlサンプル
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Authen::Wsse;
use LWP::UserAgent;
use HTTP::Request::Common;
my $id = 'ku@example.com';
my $passwd = 'PASSWORD';
my $member_id = 26756;
my $ua = LWP::UserAgent->new;
$ua->credentials('mixi.jp:80', '', $id, $passwd);
# upload image.
my $res = $ua->post(
"http://mixi.jp/atom/diary/member_id=$member_id",
'Content-Type' => 'image/jpeg',
'content' => join "", <>
);
warn $res->content unless $res->code == 201;
my $uri = $res->headers->{'location'};
# set text.
my $content = <<__XML__;
<?xml version='1.0' encoding='utf-8'?>
<entry xmlns='http://www.w3.org/2007/app'>
<title>ハロー</title>
<summary>perlからatom/diary/member_id=によるAPI経由で投稿していまうす。</summary>
</entry>
__XML__
$res = $ua->post(
$uri,
'Content-Type' => 'application/atom+xml',
'content' => $content
);
warn $res->content unless $res->code == 201;
足あとの一覧を表示するクライアントのサンプル
mixi station APIより引用
use HTTP::Date qw( str2time time2iso );
use XML::Atom::Client;
use XML::Atom::Feed;
use XML::Atom::Service 0.15.0;
my $ID = 'foo@example.com';
my $PASS = 'password';
my $URI = 'http://mixi.jp/atom/tracks';
# クライアントを設定
my $client = XML::Atom::Client->new;
$client->username( $ID );
$client->password( $PASS );
# サービス文書を取得
my $service = $client->getService( $URI );
for my $collection ( $service->workspace->collections ) {
# Feed URI を取得
my $feed_uri = $collection->href;
# フィードを取得
my $feed = $client->getFeed( $feed_uri );
# 足あとを順に表示
for my $entry ( $feed->entries ) {
# 日本時間に変換
my $datetime = time2iso( str2time( $entry->updated ) );
my ( $link ) = $entry->links;
# 表示 (日時,訪問者,訪問者の URI)
print $datetime, ' ', $entry->title, ' ', $link->href, "\n";
}
}