Web アプリケーションの開発コンテスト Mashup Awards 5 (MA5) が今年も開催! API や新しいデバイス・プラットフォームを活用した提案をお待ちします。- MA5 - Mashup Awards 5参加受付中! (Yahoo! JAPAN Tech Blog)

./gaapi.pl ga:138852 2009-10-10
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Request::Common ();
use LWP::UserAgent;
use XML::Simple;
use Data::Dumper;
my $email = 'YOU@gmail.com';
my $password = 'PASSWORD';
my $source = 'yusukebe-GoogleAnalyticsCommand-001-kai1';
my ( $req, $res, $auth_key );
my $ua = LWP::UserAgent->new();
my $xs = XML::Simple->new( KeyAttr => [''], ForceArray => ['entry'] );
auth();
if ( defined $ARGV[0] and defined $ARGV[1] ) {
analytic( { profile_id => $ARGV[0], date_string => $ARGV[1] } );
} else {
ls();
}
sub auth {
my $auth_url = 'https://www.google.com/accounts/ClientLogin';
my $service = 'analytics';
$req = HTTP::Request::Common::POST(
$auth_url,
[
accountType => 'GOOGLE',
Email => $email,
Passwd => $password,
service => $service,
source => $source
]
);
$res = $ua->request($req);
die $res->status_line if $res->is_error;
my $content = $res->content;
if ( $res->content =~ /Auth=([^\s]+)/ ) {
$auth_key = $1;
} else {
die "can't find auth key!";
}
}
sub analytic {
my $args = shift;
my $feed_url = 'https://www.google.com/analytics/feeds/data';
my $profile_id = $args->{profile_id};
my $date_string = $args->{date_string};
$feed_url =
"$feed_url?ids=$args->{profile_id}&metrics=ga:pageviews".
"&start-date=$args->{date_string}&end-date=$args->{date_string}".
"&prettyprint=true"; #xxx
$res = $ua->request(
HTTP::Request::Common::GET(
$feed_url, 'Authorization' => "GoogleLogin Auth=$auth_key"
)
);
my $ref = $xs->XMLin( $res->content );
print Dumper($ref), "\n";
}
sub ls {
$res = $ua->request(
HTTP::Request::Common::GET(
'https://www.google.com/analytics/feeds/accounts/default?prettyprint=true',
'Authorization' => "GoogleLogin Auth=$auth_key"
)
);
my $ref = $xs->XMLin( $res->content );
print Dumper($ref), "\n";
}


キーボードで「ああ」とか「なななんと」など、ア段の音を連続入力する方法は載ってますか?載ってますよ!