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


Python Facebook.load_signed_request方法代码示例

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


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

示例1: init_facebook

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import load_signed_request [as 别名]
    def init_facebook(self):
        """Sets up the request specific Facebook and User instance"""
        facebook = Facebook()
        user = None

        # initial facebook request comes in as a POST with a signed_request
        if u'signed_request' in self.request.POST:
            facebook.load_signed_request(self.request.get('signed_request'))
            # we reset the method to GET because a request from facebook with a
            # signed_request uses POST for security reasons, despite it
            # actually being a GET. in webapp causes loss of request.POST data.
            self.request.method = u'GET'
            self.set_cookie(
                'u', facebook.user_cookie, datetime.timedelta(minutes=1440))
        elif 'u' in self.request.cookies:
            facebook.load_signed_request(self.request.cookies.get('u'))

        # try to load or create a user object
        if facebook.user_id:
            user = User.get_by_key_name(facebook.user_id)
            if user:
                # update stored access_token
                if facebook.access_token and \
                        facebook.access_token != user.access_token:
                    user.access_token = facebook.access_token
                    user.put()
                # refresh data if we failed in doing so after a realtime ping
                if user.dirty:
                    user.refresh_data()
                # restore stored access_token if necessary
                if not facebook.access_token:
                    facebook.access_token = user.access_token

            if not user and facebook.access_token:
                me = facebook.api(u'/me', {u'fields': u'picture,friends'})
                user = User(key_name=facebook.user_id,
                    user_id=facebook.user_id,
                    access_token=facebook.access_token,
                    name=me[u'name'],
                    email=me.get(u'email'),  # optional
                    picture=me[u'picture'],
                    friends=[user[u'id'] for user in me[u'friends'][u'data']])
                user.put()

        self.facebook = facebook
        self.user = user
开发者ID:phoenix24,项目名称:fb-apps,代码行数:48,代码来源:main.py


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