当前位置: 首页>>代码示例>>Python>>正文


Python Facebook.get_add_url方法代码示例

本文整理汇总了Python中facebook.Facebook.get_add_url方法的典型用法代码示例。如果您正苦于以下问题:Python Facebook.get_add_url方法的具体用法?Python Facebook.get_add_url怎么用?Python Facebook.get_add_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在facebook.Facebook的用法示例。


在下文中一共展示了Facebook.get_add_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import get_add_url [as 别名]
  def post(self):
    fb = Facebook(settings.key.api, settings.key.secret)
    logging.debug('Created Facebook instance')

    # Checks to make s  ure that the user is logged into Facebook.
    if fb.check_session(self.request):
      pass
    else:
      # If not redirect them to your application add page.
      url = fb.get_add_url()
      self.response.out.write('<fb:redirect url="' + url + '" />')
      return

    # Checks to make sure the user has added your application.
    if fb.added:
      pass
    else:
      # If not redirect them to your application add page.
      url = fb.get_add_url()
      self.response.out.write('<fb:redirect url="' + url + '" />')
      return
    
    greeting = Greeting()
    greeting.uid = fb.uid
    greeting.content = self.request.get('content')
    greeting.put()
    self.redirect('/')
开发者ID:sidonath,项目名称:gaestbook,代码行数:29,代码来源:gaestbook.py

示例2: FacebookRequestHandler

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import get_add_url [as 别名]
class FacebookRequestHandler(RequestHandler):
    """
    Base class for request handlers for Facebook apps, providing useful
    Facebook-related tools: a local 
    """

    def _fbconfig_value(self, name, default=None):
        """
        Checks the global config dictionary and then for a class/instance
        variable, using a provided default if no value is found.
        """
        if name in FACEBOOK_CONFIG:
            default = FACEBOOK_CONFIG[name]

        return getattr(self, name, default)

    def initialize(self, request, response):
        """
        Initialize's this request's Facebook client.
        """
        super(FacebookRequestHandler, self).initialize(request, response)

        app_name = self._fbconfig_value("app_name", "")
        api_key = self._fbconfig_value("api_key", None)
        secret_key = self._fbconfig_value("secret_key", None)

        self.facebook = Facebook(api_key, secret_key, app_name=app_name)

        require_app = self._fbconfig_value("require_app", False)
        require_login = self._fbconfig_value("require_login", False)
        need_session = self._fbconfig_value("need_session", False)
        check_session = self._fbconfig_value("check_session", True)

        self._messages = None
        self.redirecting = False

        if require_app or require_login:
            if not self.facebook.check_session(request):
                self.redirect(self.facebook.get_login_url(next=request.url))
                self.redirecting = True
                return
        elif check_session:
            self.facebook.check_session(request)  # ignore response

        # NOTE: require_app is deprecated according to modern Facebook login
        #       policies. Included for completeness, but unnecessary.
        if require_app and not self.facebook.added:
            self.redirect(self.facebook.get_add_url(next=request.url))
            self.redirecting = True
            return

        if not (require_app or require_login) and need_session:
            self.facebook.auth.getSession()

    def redirect(self, url, **kwargs):
        """
        For Facebook canvas pages we should use <fb:redirect /> instead of
        a normal redirect.
        """
        if self.facebook.in_canvas:
            self.response.clear()
            self.response.out.write('<fb:redirect url="%s" />' % (url,))
        else:
            super(FacebookRequestHandler, self).redirect(url, **kwargs)

    def add_user_message(self, kind, msg, detail="", time=15 * 60):
        """
        Add a message to the current user to memcache.
        """
        if self.facebook.uid:
            key = "messages:%s" % self.facebook.uid
            self._messages = memcache.get(key)
            message = {"kind": kind, "message": msg, "detail": detail}
            if self._messages is not None:
                self._messages.append(message)
            else:
                self._messages = [message]
            memcache.set(key, self._messages, time=time)

    def get_and_delete_user_messages(self):
        """
        Get all of the messages for the current user; removing them.
        """
        if self.facebook.uid:
            key = "messages:%s" % self.facebook.uid
            if not hasattr(self, "_messages") or self._messages is None:
                self._messages = memcache.get(key)
            memcache.delete(key)
            return self._messages
        return None
开发者ID:Mondego,项目名称:pyreco,代码行数:92,代码来源:allPythonContent.py


注:本文中的facebook.Facebook.get_add_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。