Пример #1
0
    def wrapper(request, *args, **kwargs):
        user = request.user

        # User must me logged via FB backend in order to ensure we talk about
        # the same person
        if not is_complete_authentication(request):
            try:
                user = social_complete(request, FacebookBackend.name)
            except ValueError:
                pass  # no matter if failed

        # Not recommended way for FB, but still something we need to be aware
        # of
        if isinstance(user, HttpResponse):
            kwargs.update({'auth_response': user})
        else:  # Need to re-check the completion
            if is_complete_authentication(request):
                kwargs.update({'access_token': get_access_token(request.user)})
            else:
                request.user = AnonymousUser()

        signed_request = FacebookBackend().load_signed_request(
            request.REQUEST.get('signed_request', ''))
        if signed_request:
            kwargs.update({'signed_request': signed_request})

        return func(request, *args, **kwargs)
Пример #2
0
    def fetch_friends(self, user, paginate=False):
        """
        fethces friends from facebook using the oauth_token
        fethched by django-social-auth.

        Note - user isn't a user - it's a UserSocialAuth if using social auth, or a SocialAccount if using allauth

        Returns:
            collection of friend objects fetched from facebook
        """

        if USING_ALLAUTH:
            social_app = SocialApp.objects.get_current('facebook')
            oauth_token = SocialToken.objects.get(account=user,
                                                  app=social_app).token
        else:
            social_auth_backend = FacebookBackend()

            # Get the access_token
            tokens = social_auth_backend.tokens(user)
            oauth_token = tokens['access_token']

        graph = facebook.GraphAPI(oauth_token)

        friends = graph.get_connections("me", "friends")

        if paginate:
            total_friends = friends.copy()
            total_friends.pop('paging')
            while 'paging' in friends and 'next' in friends[
                    'paging'] and friends['paging']['next']:
                next_url = friends['paging']['next']
                next_url_parsed = urlparse.urlparse(next_url)
                query_data = urlparse.parse_qs(next_url_parsed.query)
                query_data.pop('access_token')
                for k, v in query_data.items():
                    query_data[k] = v[0]
                friends = graph.get_connections("me", "friends", **query_data)
                total_friends['data'] = sum(
                    [total_friends['data'], friends['data']], [])
        else:
            total_friends = friends

        return total_friends
    def fetch_friends(self, user, paginate=False):
        """
        fethces friends from facebook using the oauth_token
        fethched by django-social-auth.

        Note - user isn't a user - it's a UserSocialAuth if using social auth, or a SocialAccount if using allauth

        Returns:
            collection of friend objects fetched from facebook
        """

        if USING_ALLAUTH:
            social_app = SocialApp.objects.get_current('facebook')
            oauth_token = SocialToken.objects.get(account=user, app=social_app).token
        else:
            social_auth_backend = FacebookBackend()

            # Get the access_token
            tokens = social_auth_backend.tokens(user)
            oauth_token = tokens['access_token']

        graph = facebook.GraphAPI(oauth_token)

        friends = graph.get_connections("me", "friends")

        if paginate:
            total_friends = friends.copy()
            total_friends.pop('paging')
            while 'paging' in friends and 'next' in friends['paging'] and friends['paging']['next']:
                next_url = friends['paging']['next']
                next_url_parsed = urlparse.urlparse(next_url)
                query_data = urlparse.parse_qs(next_url_parsed.query)
                query_data.pop('access_token')
                for k, v in query_data.items():
                    query_data[k] = v[0]
                friends = graph.get_connections("me", "friends", **query_data)
                total_friends['data'] = sum([total_friends['data'], friends['data']], [])
        else:
            total_friends = friends

        return total_friends
    def fetch_friends(self, user):
        """
        fethces friends from facebook using the oauth_token
        fethched by django-social-auth.

        Note - user isn't a user - it's a UserSocialAuth if using social auth, or a SocialAccount if using allauth

        Returns:
            collection of friend objects fetched from facebook
        """

        if USING_ALLAUTH:
            social_app = SocialApp.objects.get_current("facebook")
            oauth_token = SocialToken.objects.get(account=user, app=social_app).token
        else:
            social_auth_backend = FacebookBackend()

            # Get the access_token
            tokens = social_auth_backend.tokens(user)
            oauth_token = tokens["access_token"]

        graph = facebook.GraphAPI(oauth_token)

        return graph.get_connections("me", "friends")
Пример #5
0
    def fetch_friends(self, user):
        """
        fethces friends from facebook using the oauth_token
        fethched by django-social-auth.

        Note - user isn't a user - it's a UserSocialAuth if using social auth, or a SocialAccount if using allauth

        Returns:
            collection of friend objects fetched from facebook
        """

        if USING_ALLAUTH:
            social_app = SocialApp.objects.get_current('facebook')
            oauth_token = SocialToken.objects.get(account=user, app=social_app).token
        else:
            social_auth_backend = FacebookBackend()

            # Get the access_token
            tokens = social_auth_backend.tokens(user)
            oauth_token = tokens['access_token']

        graph = facebook.GraphAPI(oauth_token)

        return graph.get_connections("me", "friends")