Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8047505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:07:19+00:00 2026-06-05T06:07:19+00:00

I’m using the Python based Social Cookbook template to create a Facebook App, but

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:07:22+00:00Added an answer on June 5, 2026 at 6:07 am

    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.

    class BaseHandler(tornado.web.RequestHandler):
        @property
        def prepare(self):
            self.set_header('P3P', 'CP="HONK"')
    
        def initialize(self):
            if self.request.full_url() == "http://mydomain/a/facebook/":
                self.request.protocol = "https"
            self.init_facebook()
    
        def init_facebook(self):
            """Sets up the request specific Facebook and User instance"""
    
            # 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")
                if user_id:
                    self.set_secure_cookie("uid", user_id)
                self.request.method = u'GET'
    
    class FacebookCanvasHandler(HomeHandler):
        def get(self, *args, **kwds):
            logging.info("Facebook Canvas called.")
            if not self.current_user:
                logging.info("Need user grant permission, redirect to oauth dialog.")
                logging.info(self.settings.get("facebook_canvas_id"))
                oauth_url = self.get_login_url(self.settings.get("facebook_canvas_id"))
                logging.info(oauth_url)
                self.render("canvas_oauth.html", oauth_url=oauth_url)
            else:
                super(FacebookCanvasHandler, self).get(*args, **kwds)
    
    def load_signed_request(signed_request, app_secret):
        try:
            sig, payload = signed_request.split(u'.', 1)
            sig = base64_url_decode(sig)
            data = json.loads(base64_url_decode(payload))
    
            expected_sig = hmac.new(app_secret, msg=payload, digestmod=hashlib.sha256).digest()
    
            if sig == expected_sig and data[u'issued_at'] > (time.time() - 86400):
                return data
            else:
                return None
        except ValueError, ex:
            return None
    
    def base64_url_decode(data):
        data = data.encode(u'ascii')
        data += '=' * (4 - (len(data) % 4))
        return base64.urlsafe_b64decode(data)
    

    canvans_oauth.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>
            Page Title
        </title>
        <meta name="description" content="description of the page" /><meta name="keywords" content="" /><meta name="viewport" content="width=device-width" />
        <link rel="icon" type="image/png" href="/static/favicon.ico" />
        <script>
            window.top.location = "{% raw oauth_url %}";
        </script>
    
    </head>
    
    <body id="inner_body" class="inner_body">
    redirecting to oauth...
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using Paperclip to handle profile photo uploads in my app. They upload
I am writing an app with both english and french support. The app requests
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.