Creating a Like-Gate (Open Tab) for a Facebook Application Using Django / Python

I am creating a Facebook application using Python / Django. I installed FanDjango and it works great. One more thing I need.

I would like to create a "like-gate" for the browser. I want the application to detect that the user has "liked" on the Fan page before they can view the main body. I haven't found a good solution for this yet.

I am wary of using something like PyFacebook. Can anyone suggest a good option? Thank.


source to share

3 answers

Thank. I got this to work by reading the documentation in the personal module I installed. Here's how you access user-like information for a specific page:

from facepy import SignedRequest
if 'signed_request' in request.REQUEST:
    signed_request = SignedRequest.parse(request.REQUEST.get('signed_request'), settings.FACEBOOK_APPLICATION_SECRET_KEY)
    test = "yes!"
    test = "no!"  




Fandjango wraps the face, so it's actually easier. Install only Fandjango via pip to avoid conflicts.

In view with request object, you can just check


and perform different actions. Remember the page will be None if the app is not on the page.



I'm not a Facebook expert and haven't played around with Facebook graph that much, but this should work.

Once you authenticate the user, you can get your preferences from the Facebook graph:{your_contents_graph_id}?access_token={access_token}


In Python, I can request this via:

import requests
url = "{your_contents_graph_id}?access_token={access_token}".format(your_contents_graph_id=your_contents_graph_id, access_token=access_token)
r = request.get(url)
if r.status_code == '200':
    page_liked = True
    page_liked = False


All that said, I would not like your content. Doesn't fit me or someone else likes something that they haven't fully viewed. You might want to consider an alternative way to get people to watch your content.



All Articles