gpt4 book ai didi

python - django_facebook 应用程序中的链接导致错误请求 : missing signed_request

转载 作者:太空宇宙 更新时间:2023-11-04 06:20:58 25 4
gpt4 key购买 nike

我正在使用安装在 pythonanywhere 上的 django_facebook 库。当我单击从一个 View 到另一个 View 的链接时,我收到一条错误消息:

400 Bad Request

Missing signed_request.

谁能简要介绍一下链接在 Facebook 应用程序中的工作原理?

删除 @canvas_only 装饰器并不能解决问题,因为我需要访问图形 API。

代码如下:

views.py:

from django.shortcuts import render
from django_facebook.decorators import canvas_only
#from django_facebook.decorators import facebook_required
#from django.utils.decorators import method_decorator

from models import Poem, Share
from django import forms
from django.views.generic import View

class PoemEntryForm(forms.Form):
words = forms.CharField( widget=forms.widgets.Textarea(), initial='ENTER\nPOEM\nHERE\nONE\nWORD\nPER\nLINE' )

@canvas_only
def home(request):
me = request.facebook.graph.get_object('me')
my_username = me['username']
request.session['username'] = my_username

try:
poems = Poem.objects.filter(user=my_username)
except Poem.DoesNotExist:
poems = []

# convert poems into tuples of information relevant to the home page
# sort them in reverse chronological order
# ie: title and created
poems = [(poem.title(), poem.created) for poem in sorted(poems, key=lambda poem: poem.created, reverse=True)]

try:
shared = Share.objects.filter(shared_to=my_username)
except Share.DoesNotExist:
shared = []

shared = [(poem.title(), poem.user, poem.created) for poem in sorted(shared, key=lambda poem: poem.created, reverse=True)]

return render(request, 'home.html', {
'me': me,
'my_poems': poems,
'shared': shared,
})

class Create(View):
#@method_decorator(canvas_only)
def get(self, request, *args, **kwargs):
#self.me = request.facebook.graph.get_object('me')
form = PoemEntryForm(request.GET)
return render(request, 'create.html', {
'form': form,
'debug': request.session['username']
})

#@method_decorator(canvas_only)
def post(self, request, *args, **kwargs):
if request.session['username']:
form = PoemEntryForm(request.POST)
poem = Poem()
poem.user = request.session['username']
poem.text = request.POST['words']
poem.save()
return render(request, 'submitted.html', {})
else:
return render(request, 'error_submitting.html', {})

提交.html:

<html>
<body>
<h3>You submitted a poem</h3>
<a href="https://finebitstrings.pythonanywhere.com/">Home</a>
</body>
</html>

最佳答案

所以交易是这样的。当 django 或任何正在做回复的回复:missing signed_request. 时,它的真正意思是 session 不包含键 'signed_request' 的条目.您可以在初始请求的 POST 数据中找到此请求。将其保存在 session 中,您就可以开始了。

关于python - django_facebook 应用程序中的链接导致错误请求 : missing signed_request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12229232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com