0

I am building a page tab for my site, it needs to custom by facebook's page id, that's why I created a view for this.

@csrf_exempt
def iframe_playlist(request):
code = request.REQUEST.get("signed_request", None)
code = 'none' if code == None else 'none'
return HttpResponse(code) #<<< I tried to output the request 
                #<<< and see if the request exists. but it always shows to none.
code = code.split('.', 2)
code = facebook.base64_url_encode(code)
code = json.loads(code)
uid = json['user_id']
site_user = get_object_or_404(FacebookProfile, uid=uid)
app = get_object_or_404(AppPage, user=site_user.user)
playlist = app.playlist
image = app.image if app.image else None
Shegit Brahm
  • 725
  • 2
  • 9
  • 22
genxstylez
  • 276
  • 1
  • 4
  • 11

1 Answers1

0

I see a few different errors, most important one is in this line:

code = 'none' if code == None else 'none'

It basically says:

code = 'none' # Always!

No wonder that next lines always prints "none" ;) Moreover, you should use if code is None instead of if code == None, it's very important!

What you really need is to change these lines:

 code = request.REQUEST.get("signed_request", None)
 code = 'none' if code == None else 'none'

to:

code = request.REQUEST.get("signed_request", 'none')

And later on, when the code works, you won't even need to set string value "none" - it's just for debugging as I understand.

Additionally, the "signed_request" should be passed as POST by Facebook. And according to Django docs:

It's strongly suggested that you use GET and POST instead of REQUEST, because the former are more explicit.

If the first hint doesn't help, please check if your URL is correct, according to this: Facebook iframe tab signed request always empty

Community
  • 1
  • 1
Jakub Gocławski
  • 3,282
  • 1
  • 18
  • 12