[facebook]友達情報の取得
facebookアプリで、外部アプリでFQLを使って友達の誕生日を取得する例です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
package Main; use 5.0008; use strict; use base qw(CGI::Application); use Facebook::Graph; use Encode; sub cgiapp_init { my $self = shift; $fb = Facebook::Graph->new( app_id => 'xxxxxxx', secret => 'yyyyyyy', postback => 'http://hoge.jp/demo.cgi?rm=callback', ); } sub doConnect{ my($self, $err) = @_; my $uri = $fb->authorize->extend_permissions(qw/friends_birthday/)->uri_as_string; return $self->redirect( $uri ); } 誕生日の未入力(非表示もか?)のデータを除去しています。 sub doList{ my($self, $err) = @_; my $q = $self->query(); my $fql = "SELECT uid, name,birthday_date FROM user WHERE birthday_date!='' AND uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY birthday_date"; my $frinfo = $fb->fql( $fql ); my $ff = $frinfo->{data}; foreach my $friend ( @$ff ){ $fbuf .= "["; $fbuf .= "uid:$friend->{uid}/"; $fbuf .= "name:" . Encode::encode("utf8", $friend->{name}) . "/"; $fbuf .= "birthday:$friend->{birthday_date}"; $fbuf .= "]<br />"; } } |