Mysterious problem with Fandjango

2019-07-12 18:53发布

问题:

I've just configured fandjango with my simply django application.

Here's the files:

VIEWS.PY

from django.http import HttpResponse
from django.shortcuts import render
from fandjango.decorators import facebook_authorization_required

@facebook_authorization_required()
def home(request):
    return render(request, 'home.html', {'facebook_user': request.facebook.user})

HOME.HTML

{% if facebook_user.first_name %}
You are:<br>

{{ facebook_user.first_name }} {{ facebook_user.last_name }}.
<br>ID: {{ facebook_user.facebook_id }}
<br>YOUR URL: {{ facebook_user.profile_url }}
<br><img src="http://graph.facebook.com/{{ facebook_user.facebook_id }}/picture?type=large">

{% else %}There's a problem here.{% endif %}

Now, when I go to http://apps.facebook.org/myapplicationname and I allow the access for application to take account's infos, I see the home.html.

BUT (here's the BIG problem) sometimes I see all my infos (if condition is true) but sometimes I don't see my info and I see "There's a problem here". In the database the data is ok.

I've checked this with others account and there's still this mysterious problem.

回答1:

Instead of doing
{% if facebook_user.first_name %}
check for
{% if facebook.user %}

That will actually check for the user if he was authorized; the first one may give you random errors -missing first name on some users maybe-.



回答2:

Do you have caching turned on in your application? Does the problem occur more or less when you do a full refresh?

Is facebook limiting your calls to the authentication API?

Does fandjango properly cache those? Does your problem show up most often if you refresh the page a bunch of times, but goes away if you leave it alone for a while and come back?

Are you actually running the latest version of fandjango?