在 Django 中响应 Instagram webhook
Respond to Instagram webhook in Django
我为Instagram webhook设置了回调-url,当Instagram获取我的回调-url我应该回复hub.challenge来验证。 Instagram GET 请求到我的端点 URL:
GET https://callback_url/webhooks?
hub.mode=subscribe&
hub.challenge=1120110039&
hub.verify_token=meatyhamhock
我的代码在vews.py:
def getInstagramWebhook(request):
if request.method == "GET":
mode = request.GET.get("hub.mode")
challenge = request.GET.get("hub.challenge")
verify_token = request.GET.get("hub.verify_token")
return challenge
但是我有这个错误:
The URL couldn't be validated. Response does not match challenge, expected value="1120110039", received="\u003C!DOCTYPE html>\n\u003Chtm..."
我尝试了 JsonResponse、HttpResponse 和重定向,但没有用
我终于找到了解决问题的方法:)
我在回复中添加了content_type='text/plain'
:
return HttpResponse(challenge, content_type='text/plain')
Facebook 验证了我的 callback URL
我为Instagram webhook设置了回调-url,当Instagram获取我的回调-url我应该回复hub.challenge来验证。 Instagram GET 请求到我的端点 URL:
GET https://callback_url/webhooks?
hub.mode=subscribe&
hub.challenge=1120110039&
hub.verify_token=meatyhamhock
我的代码在vews.py:
def getInstagramWebhook(request):
if request.method == "GET":
mode = request.GET.get("hub.mode")
challenge = request.GET.get("hub.challenge")
verify_token = request.GET.get("hub.verify_token")
return challenge
但是我有这个错误:
The URL couldn't be validated. Response does not match challenge, expected value="1120110039", received="\u003C!DOCTYPE html>\n\u003Chtm..."
我尝试了 JsonResponse、HttpResponse 和重定向,但没有用
我终于找到了解决问题的方法:)
我在回复中添加了content_type='text/plain'
:
return HttpResponse(challenge, content_type='text/plain')
Facebook 验证了我的 callback URL