1# documentation: http://wiki.developers.facebook.com/index.php/Category:API_functions 2 3package require rest 4package require tls 5::http::register https 443 [list ::tls::socket] 6package require md5 7 8set facebook(auth.createToken) { 9 description {Creates an auth_token to be passed in as a parameter to 10 loginLink and then to auth.getSession after the user has 11 logged in. The user must log in soon after you create this 12 token. } 13 url http://api.facebook.com/restserver.php 14 method post 15 auth { sign sign } 16 req_args { api_key: secret: } 17 static_args { v 1.0 format json method Auth.createToken } 18 check_result { {} {[string match "\{error_code*" $result]} } 19 post_transform { return [string trim $result \"] } 20} 21 22set facebook(auth.getSession) { 23 url https://api.facebook.com/restserver.php 24 method post 25 auth { sign sign } 26 req_args { api_key: auth_token: secret: } 27 static_args { v 1.0 format json method Auth.getSession } 28 check_result { {} {[string match "\{error_code*" $result]} } 29} 30 31set facebook(friends.get) { 32 url http://api.facebook.com/restserver.php 33 auth { sign sign } 34 req_args { api_key: secret: call_id: } 35 opt_args { session_key: flid: uid: } 36 static_args { v 1.0 format json method Friends.get } 37 post_transform { return [split [string trim $result \[\]] ,] } 38 check_result { {} {[string match "\{error_code*" $result]} } 39} 40 41set facebook(users.getInfo) { 42 url http://api.facebook.com/restserver.php 43 auth { sign sign } 44 req_args { api_key: secret: call_id: uids: fields: } 45 opt_args { session_key: } 46 static_args { v 1.0 format json Users.getInfo } 47 check_result { {} {[string match "\{error_code*" $result]} } 48} 49 50set facebook(users.setStatus) { 51 url http://api.facebook.com/restserver.php 52 auth { sign sign } 53 req_args { api_key: secret: call_id: } 54 opt_args { session_key: status: clear: status_includes_verb: uid: } 55 static_args { v 1.0 format json Users.setStatus } 56 check_result { {} {[string match "\{error_code*" $result]} } 57} 58 59set facebook(groups.get) { 60 url http://api.facebook.com/restserver.php 61 auth { sign sign } 62 req_args { api_key: secret: session_key: call_id: } 63 opt_args { gids: uid: } 64 static_args { v 1.0 format json method Groups.get } 65 check_result { {} {[string match "\{error_code*" $result]} } 66} 67 68set facebook(notifications.get) { 69 url http://api.facebook.com/restserver.php 70 auth { sign sign } 71 req_args { api_key: secret: session_key: call_id: } 72 static_args { v 1.0 format json method Notifications.get } 73 check_result { {} {[string match "\{error_code*" $result]} } 74} 75 76rest::create_interface facebook 77 78proc ::facebook::sign {query} { 79 set str "" 80 set secret [dict get $query secret] 81 set query [dict remove $query secret] 82 foreach x [lsort [dict keys $query]] { 83 append str $x=[dict get $query $x] 84 } 85 append str $secret 86 dict append query sig [string tolower [md5::md5 -hex $str]] 87 return $query 88} 89 90proc ::facebook::loginLink {args} { 91 set query [lindex [::rest::parse_opts {} {api_key: auth_token:} {} $args] 0] 92 return http://www.facebook.com/login.php?api_key=[dict get $query api_key]&v=1.0&auth_token=[dict get $query auth_token] 93} 94