(module example mzscheme
(require "flickr.ss")
(current-api-key "*********")
(current-sec-key "*********")
(require (lib "external.ss" "browser")
(lib "url.ss" "net")
(lib "match.ss")
(lib "file.ss"))
(define (exn:flickr:invalid-auth-token? exn)
(and (exn:flickr? exn)
(= 98 (exn:flickr-code exn))))
(define (authenticate!)
(parameterize ((sign-all? #t))
(match (flickr.auth.getFrob)
[(('frob () frob))
(begin
(send-url (url->string (authorize-url #:frob frob #:perms "read")))
(read) (parameterize ((non-text-tags (list* 'auth (non-text-tags))))
(match (flickr.auth.getToken #:frob frob)
[(('auth ()
('token () token)
('perms () perms)
('user (('fullname fn) ('nsid nsid) ('username user)))))
(put-preferences (list 'flickr:token) (list token))])))])))
(define (maybe-authenticate!)
(let ((auth-token (get-preference 'flickr:token)))
(if auth-token
(with-handlers ((exn:flickr:invalid-auth-token?
(lambda (exn) (authenticate!))))
(parameterize ((sign-all? #t))
(flickr.auth.checkToken #:auth_token auth-token)
(values)))
(authenticate!))))
(define (run-example!)
(maybe-authenticate!)
(parameterize ((non-text-tags (list* 'photos (non-text-tags)))
(sign-all? #t))
(match (flickr.photos.search #:user_id "me" #:auth_token (get-preference 'flickr:token))
[(('photos _ ('photo (('farm farm)
('id id)
('isfamily _)
('isfriend _)
('ispublic _)
('owner owner)
('secret secret)
('server server)
('title _))) . rest))
(send-url
(format "http://farm~a.static.flickr.com/~a/~a_~a_t.jpg"
farm server id secret))])))
)