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.

+3


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)
if signed_request.page.is_liked:
    test = "yes!"
else:
    test = "no!"  

      

+2


source


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



request.facebook.signed_request.page.is_liked

      

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

+2


source


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:

https://graph.facebook.com/me/likes/{your_contents_graph_id}?access_token={access_token}

      

In Python, I can request this via:

import requests
url = "https://graph.facebook.com/me/likes/{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
else:
    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.

+1


source







All Articles