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