Here is some code combining minifb.py with web.py framework
Assumes your Callback url is
http://<public IP>:8080/fb/
----------------------------
import web
import minifb
_FbApiKey = "<your API key>"
_FbSecret = minifb.FacebookSecret("<Your Secret key>")
_CanvasURL = "<Your canvas URL>"
_RegURL = '
http://www.facebook.com/add.php?api_key=' + _FbApiKey
render = web.template.render('templates/')
urls = (
'/fb/', 'index',
'/fb/add', 'add',
'/fb/remove', 'remove',
)
app = web.application(urls, locals())
def minival(inp):
args = minifb.validate(_FbSecret,inp)
if args['added']==0:
return """<fb:redirect url="%s" />""" % _RegURL
return args
class index:
def POST(self):
args = minival(web.input())
# Do something on the canvas page
return render.base(_CanvasURL,render.header(""),"","")
class add:
def POST(self):
args = minival(web.input())
# Do something after the application is added
return """<fb:redirect url="%s" />""" % _CanvasURL
class remove:
def POST(self):
args = minival(web.input())
# Do something after the application is removed
return """<fb:redirect url="%s" />""" % _CanvasURL
if __name__ == "__main__":
app.run()