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


Python Facebook.check_session方法代码示例

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


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

示例1: get_user

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
def get_user(request):
    from django.contrib.auth.models import AnonymousUser

    if 'facebook' in settings.OPENAUTH_DATA :
        from facebook import Facebook
        fb = Facebook(settings.OPENAUTH_DATA['facebook']['key'], settings.OPENAUTH_DATA['facebook']['secret'])
        fb.check_session(request)
        if fb.uid is not None :
            identity = 'facebook:%s' % fb.uid
            try :
                from .models import OpenUser
                oiuser = OpenUser.objects.get(openid=identity, source='openid')
                return oiuser.user
            except OpenUser.DoesNotExist :
                pass

    try:
        auth = request.COOKIES.get(AUTH_COOKIE, '')

        parts = auth.split('|')
        if len(parts) != 4 :
            user = AnonymousUser()
        elif parts[3] == md5("|".join([parts[0], parts[1], parts[2], settings.SECRET_KEY])).hexdigest() :
            backend = load_backend(parts[2])
            user    = backend.get_user(parts[0]) or AnonymousUser()
        else :
            user = AnonymousUser()
    except KeyError:
        user = AnonymousUser()
    return user
开发者ID:koblas,项目名称:notewave,代码行数:32,代码来源:__init__.py

示例2: context_processor

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
def context_processor(request) :
    key = None
    if 'facebook' in settings.OPENAUTH_DATA and 'key' in settings.OPENAUTH_DATA['facebook'] :
        key = settings.OPENAUTH_DATA['facebook']['key']

    result = {}

    user = get_user(request)
    if not user.is_anonymous() :
        from views import GENERATED_USERBASE
        result.update({
            'openauth' : {
                'need_name'   : len(user.get_full_name()) == 0,
                #'need_screen' : user.username.find(GENERATED_USERBASE) == 0,
                'need_email'  : user.email == '',
            }
        })

    inCanvas = False
    if 'facebook' in settings.OPENAUTH_DATA :
        from facebook import Facebook
        fb = Facebook(settings.OPENAUTH_DATA['facebook']['key'], settings.OPENAUTH_DATA['facebook']['secret'])
        fb.check_session(request)
        inCanvas = fb.in_canvas

    result.update({
                'facebook' : {
                    'apikey' : key,
                    'inCanvas' : inCanvas,
                }
            })

    return result
开发者ID:koblas,项目名称:notewave,代码行数:35,代码来源:__init__.py

示例3: post

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [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

示例4: authenticate

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
 def authenticate(self, request):
     """
     Started at 
         http://github.com/uswaretech/Django-Socialauth/blob/master/socialauth/auth_backends.py
     
     Made massive improvements with error handling.
     """
     facebook =  Facebook(settings.FACEBOOK_API_KEY, settings.FACEBOOK_SECRET_KEY)
     check = facebook.check_session(request)
     clear_permissions(request) # for internal perms
     try:
         fb_user = facebook.users.getLoggedInUser()
         fb_data = get_fb_data(facebook, fb_user)
         
         profile = FacebookUserProfile.objects.get(facebook_uid = unicode(fb_user))            
     except FacebookUserProfile.DoesNotExist:
         username = 'FB:%s' % fb_data['uid']
         fb_user,new_user = User.objects.get_or_create(username = username)
         fb_user.is_active = True
         fb_user.first_name = fb_data['first_name']
         fb_user.last_name = fb_data['last_name']
         fb_user.email = fb_data['email']
         fb_user.save()
         
         try:
             profile = FacebookUserProfile(facebook_uid= unicode(fb_data['uid']), user=fb_user)
             profile.save()
             auth_meta = AuthMeta(user=user, provider='Facebook').save()
         except:
             pass
     except Exception, e:
         return None
开发者ID:eos87,项目名称:secretapp,代码行数:34,代码来源:backends.py

示例5: facebook_connect

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
def facebook_connect(request, template='socialregistration/facebook.html', extra_context=dict()):
    """
    View to handle connecting existing accounts with facebook
    """
    fb = Facebook(settings.FACEBOOK_API_KEY, settings.FACEBOOK_SECRET_KEY)
    if not fb.check_session(request) \
        or not request.user.is_authenticated():
        extra_context.update(
            dict(error=FB_ERROR)
        )
        return render_to_response(
            template,
            extra_context,
            context_instance=RequestContext(request)
        )

    try:
        profile = FacebookProfile.all().filter('uid=',fb.uid).fetch(1)[0]
    except IndexError:
        fb_profile = fb.users.getInfo(fb.uid, ['name','email','pic_square','username', ])[0]
        profile = FacebookProfile(user=request.user,
            uid=fb.uid,
            username = fb_profile['username'],
            real_name = fb_profile['name'],
            email = fb_profile['email'],
            pic_url = fb_profile['pic_square'],
            )
        profile.save()


    return HttpResponseRedirect(_get_next(request))
开发者ID:frankk00,项目名称:social-auth-for-django-appengine,代码行数:33,代码来源:views.py

示例6: authenticate

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
    def authenticate(self, request):

        if not settings.FACEBOOK_API_KEY in request.COOKIES:
            return None

        facebook =  Facebook(settings.FACEBOOK_API_KEY,
                             settings.FACEBOOK_SECRET_KEY)
                             
        check = facebook.check_session(request)
        fb_user = facebook.users.getLoggedInUser()

        try:
            profile = FacebookUserProfile.objects.get(facebook_uid = fb_user)
            return profile.user
        except FacebookUserProfile.DoesNotExist:
            fb_data = facebook.users.getInfo([fb_user], ['uid', 'first_name', 'last_name', 'pic_small', 'current_location'])
            if not fb_data:
                return None
            fb_data = fb_data[0]

            username = 'FB:%s' % fb_data['uid']
            user_email = '%[email protected]%s.com'%(fb_data['first_name'], settings.SITE_NAME)
            user = User.objects.create(username = username, email=user_email)
            user.first_name = fb_data['first_name']
            user.last_name = fb_data['last_name']
            user.save()
            location = str(fb_data['current_location'])
            fb_profile = FacebookUserProfile(facebook_uid = fb_data['uid'], user = user, profile_image_url = fb_data['pic_small'], location=location)
            fb_profile.save()
            auth_meta = AuthMeta(user=user, provider='Facebook').save()
            return user
        except Exception, e:
            print str(e)
开发者ID:cwjacklin,项目名称:Django-Socialauth,代码行数:35,代码来源:auth_backends.py

示例7: process_request

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
    def process_request(self, request):
        self._setcookie = []
        request.__class__.user = LazyUser()
        request._authMiddleware = self

        import settings
        if 'facebook' in settings.OPENAUTH_DATA :
            from facebook import Facebook
            fb = Facebook(settings.OPENAUTH_DATA['facebook']['key'], settings.OPENAUTH_DATA['facebook']['secret'])
            fb.check_session(request)

            request.facebook = fb
        else :
            request.facebook = None

        return None
开发者ID:koblas,项目名称:notewave,代码行数:18,代码来源:middleware.py

示例8: post

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
 def post(self):
     rating = int(cgi.escape(self.request.get("rating_select")))
     review = str(cgi.escape(self.request.get("reviewtext")))
     courseId = int(cgi.escape(self.request.get("courseId")))
     fb = Facebook(FB_API_KEY, FB_APP_SECRET)
     if fb.check_session(self.request):
         courseQuery = db.Query(Course)
         courseQuery.filter('courseId =', courseId)
         cr = CourseReview(courseID=courseId,
                           reviewText=review,
                           overallRating=rating,
                           fbUID=long(fb.uid))
         cr.put()
     self.redirect('/coursepage/?id=' + str(courseId))
开发者ID:posborne,项目名称:discgolfhub.com,代码行数:16,代码来源:discgolfhub.py

示例9: authenticate

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
    def authenticate(self, request):

        """
        if not settings.FACEBOOK_API_KEY in request.COOKIES:
            logging.debug("Could not find FACEBOOK_API_KEY in Cookies")
            return None
        """

        facebook =  Facebook(settings.FACEBOOK_API_KEY,
                             settings.FACEBOOK_SECRET_KEY)
                             
        check = facebook.check_session(request)
        fb_user = facebook.users.getLoggedInUser()

        try:
            profile = FacebookUserProfile.objects.get(facebook_uid = str(fb_user))
            return profile.user
        except FacebookUserProfile.DoesNotExist:
            fb_data = facebook.users.getInfo([fb_user], ['uid', 'about_me', 'first_name', 'last_name', 'pic_big', 'pic', 'pic_small', 'current_location', 'profile_url', 'email'])
            if not fb_data:
                return None
            fb_data = fb_data[0]

            username = 'FB:%s' % fb_data['uid']
            email = fb_data['email']
            try:
                  user = User.objects.get(email=email)
            except:
                  #user_email = '%[email protected]'%(fb_data['uid'])
                  user = User.objects.create(username = username)
                  user.first_name = fb_data['first_name']
                  user.last_name = fb_data['last_name']
                  user.save()
                  location = str(fb_data['current_location'])
                  about_me = str(fb_data['about_me'])
                  url = str(fb_data['profile_url'])
                  fb_profile = FacebookUserProfile(facebook_uid = str(fb_data['uid']), user = user, profile_image_url = fb_data['pic'], profile_image_url_big = fb_data['pic_big'], profile_image_url_small = fb_data['pic_small'], location=location, about_me=about_me, url=url)
                  fb_profile.save()
            auth_meta = AuthMeta(user=user, provider='Facebook').save()
            return user
        except Exception, e:
            print str(e)
开发者ID:OdifYltsaeb,项目名称:Django-Socialauth,代码行数:44,代码来源:auth_backends.py

示例10: authenticate

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
    def authenticate(self, request, user=None):

        """
        if not settings.FACEBOOK_API_KEY in request.COOKIES:
            logging.debug("Could not find FACEBOOK_API_KEY in Cookies")
            return None
        """

        facebook =  Facebook(settings.FACEBOOK_API_KEY,
                             settings.FACEBOOK_SECRET_KEY)
                             
        check = facebook.check_session(request)
        fb_user = facebook.users.getLoggedInUser()

        try:
            profile = FacebookUserProfile.objects.get(facebook_uid = str(fb_user))
            return profile.user
        except FacebookUserProfile.DoesNotExist:
            fb_data = facebook.users.getInfo([fb_user], ['uid', 'first_name', 'last_name'])
            if not fb_data:
                return None
            fb_data = fb_data[0]
            username = 'FB:%s' % fb_data['uid']
            if not user:
                user = User.objects.create(username = username)
                user.first_name = fb_data['first_name']
                user.last_name = fb_data['last_name']
                user.email = username + "@socialauth"
                user.save()
            fb_profile = FacebookUserProfile(facebook_uid = str(fb_data['uid']), user = user)
            fb_profile.save()
            auth_meta = AuthMeta(user=user, provider='Facebook',
                provider_model='FacebookUserProfile', provider_id=fb_profile.pk).save()
            return user
        except Exception, e:
            print str(e)
开发者ID:psidebotham,项目名称:Django-Socialauth,代码行数:38,代码来源:auth_backends.py

示例11: check_session

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
 def check_session(self, request=None):
     """The request parameter is now optional."""
     if request is None:
         request = pylons.request
     return Facebook.check_session(self, request)
开发者ID:Mondego,项目名称:pyreco,代码行数:7,代码来源:allPythonContent.py

示例12: FacebookRequestHandler

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [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

示例13: facebook_login

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
def facebook_login(request, template='socialregistration/facebook.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'):
    """
    View to handle the Facebook login
    """
    fb = Facebook(settings.FACEBOOK_API_KEY, settings.FACEBOOK_SECRET_KEY)
    if not fb.check_session(request):

        facebook_url = "http://www.facebook.com/login.php?"

        extra_context.update(
            dict(error=FB_ERROR)
        )

        args = {
            "api_key": settings.FACEBOOK_API_KEY,
            "v": "1.0",
            "fbconnect": "true",
            "display": "page",
            "next":request.build_absolute_uri( _get_next(request)),
            "return_session": "true",
        }


        #if extended_permissions:
        #    if isinstance(extended_permissions, basestring):
        #        extended_permissions = [extended_permissions]
        #    args["req_perms"] = ",".join(extended_permissions)
        #self.redirect("http://www.facebook.com/login.php?" +
        #              urllib.urlencode(args))

        facebook_url = facebook_url + urllib.urlencode(args) 

        return HttpResponseRedirect(facebook_url)



        return render_to_response(
            template, extra_context, context_instance=RequestContext(request)
        )

    user = authenticate(uid=str(fb.uid))

    if user is None:
        user = authenticate(uid=fb.uid)
        fb_profile = fb.users.getInfo(fb.uid, ['name','email','pic_square','username', ])[0]
        request.session['social_suggested_username'] = fb_profile['username']
        request.session['socialregistration_profile'] = FacebookProfile(
            uid=fb.uid,
            username = fb_profile['username'],
            real_name = fb_profile['name'],
            email = fb_profile['email'],
            pic_url = fb_profile['pic_square'],
        )
        request.session['socialregistration_user'] = User(username=''.join(fb_profile['name'].split(' ')[:2]))
        request.session['next'] = _get_next(request)
 
        return HttpResponseRedirect(reverse('socialregistration_setup'))

    if not user.is_active:
        return render_to_response(
            account_inactive_template,
            extra_context,
            context_instance=RequestContext(request)
        )

    login(request, user)

    return HttpResponseRedirect(_get_next(request))
开发者ID:frankk00,项目名称:social-auth-for-django-appengine,代码行数:70,代码来源:views.py

示例14: authenticate

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
    def authenticate(self, request):

        """
        if not settings.FACEBOOK_API_KEY in request.COOKIES:
            logging.debug("Could not find FACEBOOK_API_KEY in Cookies")
            return None
        """

        facebook = Facebook(settings.FACEBOOK_API_KEY, settings.FACEBOOK_SECRET_KEY)

        check = facebook.check_session(request)
        fb_user = facebook.users.getLoggedInUser()

        try:
            profile = FacebookUserProfile.objects.get(facebook_uid=str(fb_user))
            return profile.user
        except FacebookUserProfile.DoesNotExist:
            user = None
            fb_data = facebook.users.getInfo(
                [fb_user],
                [
                    "uid",
                    "about_me",
                    "first_name",
                    "last_name",
                    "pic_big",
                    "pic",
                    "pic_small",
                    "current_location",
                    "profile_url",
                    "email",
                ],
            )
            if not fb_data:
                return None
            fb_data = fb_data[0]

            username = "FB:%s" % fb_data["uid"]
            email = fb_data["email"]
            try:
                if not email:
                    raise
                user = User.objects.get(email=email)
            except:
                # user_email = '%[email protected]'%(fb_data['uid'])
                user = User.objects.create(username=username)
                user.first_name = fb_data["first_name"]
                user.last_name = fb_data["last_name"]
                if email:
                    user.email = email
                user.save()
                location = unicode(fb_data["current_location"])
                about_me = unicode(fb_data["about_me"])
                url = str(fb_data["profile_url"])
                fb_profile = FacebookUserProfile(
                    facebook_uid=str(fb_data["uid"]),
                    user=user,
                    profile_image_url=fb_data["pic"],
                    profile_image_url_big=fb_data["pic_big"],
                    profile_image_url_small=fb_data["pic_small"],
                    location=location,
                    about_me=about_me,
                    url=url,
                )
                fb_profile.save()
            auth_meta = AuthMeta(user=user, provider="Facebook").save()
            return user
        except Exception, e:
            print str(e)
开发者ID:twidi,项目名称:Django-Socialauth,代码行数:71,代码来源:auth_backends.py

示例15: get_facebook

# 需要导入模块: from facebook import Facebook [as 别名]
# 或者: from facebook.Facebook import check_session [as 别名]
 def get_facebook(self):
     fb = Facebook(FB_API_KEY, FB_APP_SECRET)
     if fb.check_session(self.request):
         return fb
     else:
         return None
开发者ID:posborne,项目名称:discgolfhub.com,代码行数:8,代码来源:discgolfhub.py


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