I’m using the Python based Social Cookbook template to create a Facebook App, but I’m having a problem with Canvas support which does a POST instead of a GET. The Cookbook example doesn’t include how to handle this. Based on reading this Hello World example and looking at the Run With Friends example, I’m able to get the signed request, read the data (user id, token), and set the method to GET.
However, as it continues, the Browser / Tornado Server go into a loop where it repeatedly runs the LoginHandler. Giving me an error “Firefox has detected that the server is redirecting the request for this address in a way that will never complete.” I’ve been trying to figure this out for two days and thought if anyone could help – it would be StackOverflow. Thanks for any guidance you could provide in modifying the Social Cookbook to support the Facebook Canvas.
class BaseHandler(tornado.web.RequestHandler):
def initialize(self):
self.init_facebook()
def init_facebook(self):
# initial facebook request comes in as a POST with a signed_request
signed_request = self.get_argument('signed_request', None)
if signed_request and self.request.method == u'POST':
app_secret = options.facebook_app_secret
data = load_signed_request(signed_request, app_secret)
user_id = data.get(u"user_id")
mytoken = data.get(u"oauth_token")
print mytoken
self.set_secure_cookie("uid", user_id)
self.request.method = u'GET' # causes loss of request.POST data
Ok, so here is what I ended up doing (thanks to some assistance from oDesk – Haiming Yin) and what some of my issues were. For one, the system running FireFox on the Mac had Third Party Cookies disabled. This will cause problems with the Facebook Canvas. On IE, you have to set the proper P3P headers. So all this combine made for a good headache.
canvans_oauth.html