def user_proxy(self): if not hasattr(self, "_user_proxy"): self._user_proxy = None cookie = self.request.cookies.get("fbsr_" + config.FACEBOOK_APP_ID, "") # Cookie obviously set by Facebook if cookie: response = facebook.parse_signed_request(cookie, config.FACEBOOK_APP_SECRET) # Cookie certainly set by Facebook if response: user_proxy = UserApi(response["user_id"], response["code"]) user = user_proxy.user # If not registered, save the new user if not user: graph = facebook.GraphAPI(user_proxy.access_token) profile = graph.get_object("me") if "email" in profile: user = user_proxy.put_user( response["user_id"], profile["first_name"], profile["last_name"], profile["email"] ) logging.info("New user: %s %s" %(user.first_name, user.last_name)) self._user_proxy = user_proxy return self._user_proxy
def post(self): signed_request = self.request.get("signed_request") data = parse_signed_request(signed_request, config.FACEBOOK_APP_SECRET) page_id = data["page"]["id"] self.process(page_id)