Reputation: 53
I'm building a Facebook app using Python/Django. I've installed FanDjango and that works great. Just one more thing I need.
I'd like to build a "like-gate" for the app. I'd like the app to detect whether the user has "liked" a Fan page before they can view the bulk of it. I haven't found a good solution for that yet.
I'm wary of using something like PyFacebook. Can someone suggest a good option? Thanks.
Upvotes: 3
Views: 705
Reputation: 6677
Fandjango wraps facepy so it's actually easier. Install only Fandjango via pip to avoid conflicts.
In the view with the request object, you can simply check against
request.facebook.signed_request.page.is_liked
and perform different actions. Remember that page will be None if the app is not in a page.
Upvotes: 2
Reputation: 53
Thanks. I got this to work by reading through the documentation in the facepy module I have installed. Here's how you access a user's "like" info for a particular 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!"
Upvotes: 2
Reputation: 8334
I'm no Facebook expert, and haven't played that much with the Facebook graph, but this should work.
Once you've authenticated the user, you can get their likes off the Facebook Graph:
https://graph.facebook.com/me/likes/{your_contents_graph_id}?access_token={access_token}
In Python I might query 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 this said, I wouldn't like your content. It's not appropriate for me or anyone else to like something they haven't reviewed in full. You might want to consider an alternative way to get people to look at your content.
Upvotes: 1