--- koha-facebook.cgi 2009/06/26 18:45:33 2 +++ koha-facebook.cgi 2009/06/27 16:47:05 5 @@ -1,13 +1,12 @@ #!/usr/bin/perl +# +# Facebook appliaction which use Koha's RSS search results +# 2009-06-27 Dobrica Pavlinusic +# +# Based on WWW::Facebook::API example # Copyright David Leadbeater 2007 . # Licensed under the same terms as Perl itself. -# A simple example of using WWW::Facebook::API within a facebook canvas. -# You will need to change the api_key, secret and app_path below to match your -# account. To get an api_key and secret, go to -# http://www.facebook.com/developers/editapp.php?new, choose "Use FBML" and -# enter a unique name for the canvas which you should put into app_path. - use strict; use CGI; use WWW::Facebook::API; @@ -20,11 +19,19 @@ # UI elements +my $facebook = WWW::Facebook::API->new( + api_key => $api_key, + secret => $secret, + app_path => $app_path, + parse => 1, +); + +warn dump($facebook); + sub dashboard { print qq| Search - info |; ''; @@ -44,13 +51,7 @@ ''; } - -my $facebook = WWW::Facebook::API->new( - api_key => $api_key, - secret => $secret, - app_path => $app_path, - parse => 1, -); +# dispatcher our %action_map = ( '' => \&index_page, @@ -83,14 +84,16 @@ my ( $action, $param ) = ( $q->path_info =~ m!^/(\w+)/?(.*)! ); - if ( my $s = $action_map{$action} ) { print dashboard; + + if ( my $s = $action_map{$action} ) { print qq|
|; $s->( $q, $params ); print qq|
|; } else { - div_error("Action unknown"); + print "Action $action unknown"; + warn "unknown action $action"; } # Clear session_key (for if running under FastCGI). @@ -100,26 +103,34 @@ sub index_page { my ( $q, $params ) = @_; - form($q); +warn dump($params); -=for later + form($q); # You could do this easier by using , just showing some API stuff here. +# http://wiki.developers.facebook.com/index.php/User_(FQL) my $name = "You"; - if ($params) { - my $res = - $facebook->fql->query( query => - "SELECT first_name FROM user WHERE uid=$params->{canvas_user}" ); - $name = "Hi $res->[0]->{first_name}, you"; + if ( my $uid = $params->{user} ) { + my $res = $facebook->fql->query( query => qq| + select + first_name, last_name, + is_app_user, + books, + locale + from user + where uid=$uid + | ); + warn "# $uid res = ",dump(@{$res}); + $name = "Hello $res->[0]->{first_name}, you"; } print "$name ", ( $params ? "have" : "have't" ), - " added this application. Some info."; + " added this application."; + if ( !$params ) { print "Add this application."; } -=cut }