pyfacebook
pyfacebook copied to clipboard
fb.added is always False
I'm having problems with the "added" instance variable. It seems to be sticking at False even though indeed the user has authorized the application.
Here's the relevant part of my code, I'm working in Google App Engine:
class MainPage(webapp.RequestHandler):
def get(self):
fb = facebook.Facebook(_FbApiKey, _FbSecret, app_name=_FbAppName)
if fb.check_session(self.request) and fb.added:
pass
else:
url = fb.get_add_url(next=fb.get_app_url())
self.response.out.write('<script language="javascript">top.location.href="' + url + '"</script>')
return
self.response.out.write("<html><body>You are now logged in and you added the app!</body></html>")
It's getting into an infinite redirect cycle, because fb.added is always False. The first time, check_session returns False, but after logging in and authorizing the application, it returns True. In any case, fb.added is always False.
Does this have a fix? I'm facing the same issue.
I am also seeing this... but after some testing, I don't think the fb.added check is needed (if fb.check_session(self.request): is sufficient).
It looks like users.isAddAdded call is not deprecated (see bottom of http://wiki.developers.facebook.com/index.php/API) and should use users.isAppUser instead. To add to PyFacebook, see this commit - http://github.com/woodcoder/pyfacebook/commit/cb772249fa7fc035425a3f72c378ceba88b13679
I think the issue is that the Post-Add URL no longer contains 'installed'. 'fb_sig_added' has the same result, so a change to line 1247 in facebook.py does the trick:
1244 | 1244 | if request.method == 'POST':
1245 | 1245 | params = self.validate_signature(request.POST)
1246 | 1246 | else:
1247 | | - if 'installed' in request.GET:
| 1247 | + if 'installed' in request.GET or request.GET['fb_sig_added'] == '1':
1248 | 1248 | self.added = True
I have no idea how to commit this myself. Hopefully someone more capable can do it?
@fraserharris Your fix worked for me. I used the logs from app engine to verify that sometimes facebook sends installed as of the date on this comment, but sometimes it does not and sends fb_sig_added. It can also send installed, but not fb_sig_added. The first or term clause in your fix is still necessary.
One more kind of big last issue to this. If you get the aforementioned case of installed returned, but no fb_sig_added, the fix as written above will cause an exception. The safer fix is:
if 'installed' in request.GET:
self.added = True
if 'fb_sig_added' in request.GET:
if request.GET['fb_sig_added'] == '1':
self.added = True
Again, the call to request.GET will cause an exception in the original fix if fb_sig_added is not present. The conditional to check for it first, avoids this.