Пример #1
0
    def authenticate(self, fn, request, *args, **kwargs):
        '''
        Authenticate the user

        There are three options
        a.) We have permissions, proceed with the view
        b.) We tried getting permissions and failed, abort...
        c.) We are about to ask for permissions
        '''
        oauth_url, current_uri, redirect_uri = get_oauth_url(
            request, self.scope_list, extra_params=self.extra_params)

        graph = get_persistent_graph(request, redirect_uri=redirect_uri)

        # See if we have all permissions
        permissions_granted = has_permissions(graph, self.scope_list)

        if permissions_granted:
            response = self.execute_view(
                fn, request, graph=graph, *args, **kwargs)
        elif request.REQUEST.get('attempt') == '1':
            # Doing a redirect could end up causing infinite redirects
            # If Facebook is somehow not giving permissions
            # Time to show an error page
            response = self.authentication_failed(fn, request, *args, **kwargs)
        else:
            response = self.oauth_redirect(oauth_url, redirect_uri)

        return response
Пример #2
0
def wall_post(request):
    fb = get_persistent_graph(request)
    message = request.POST.get('message')
    if message:
        fb.set('me/feed', message=message)
        messages.info(request, 'Posted the message to your wall')
        return next_redirect(request)
Пример #3
0
def remove_og_share(request):
    from django_facebook.models import OpenGraphShare
    graph = get_persistent_graph(request)
    og_share_id = request.POST.get('og_share_id')
    if og_share_id:
        shares = OpenGraphShare.objects.filter(id=og_share_id)
        for share in shares:
            share.remove(graph)
Пример #4
0
def image_upload(request):
    fb = get_persistent_graph(request)
    pictures = request.POST.getlist('pictures')

    if pictures:
        for picture in pictures:
            fb.set('me/photos', url=picture, message='the writing is one The '
                   'wall image %s' % picture)

        messages.info(request, 'The images have been added to your profile!')

        return next_redirect(request)
Пример #5
0
def wall_post(request):
    print 'example view wall post'
    print request.GET
    print request.POST
    print 'message %s'%request.POST.get('message')
    fb = get_persistent_graph(request)
    print fb
    message = request.GET.get('message')
    if message:
        fb.set('me/feed', message=message)
        messages.info(request, 'Posted the message to your wall')
        return next_redirect(request)
Пример #6
0
def open_graph_beta(request):
    '''
    Simple example on how to do open graph postings
    '''
    message = request.POST.get('message')
    if message:
        fb = get_persistent_graph(request)
        entity_url = 'http://www.fashiolista.com/item/2081202/'
        fb.set('me/fashiolista:love', item=entity_url, message=message)
        messages.info(request,
                      'Frictionless sharing to open graph beta action '
                      'fashiolista:love with item_url %s, this url contains '
                      'open graph data which Facebook scrapes' % entity_url)