0

I set the callback-url for Instagram webhook, and when Instagram Get my callback-url I should respond to the hub.challenge to verify. Instagram GET request to my endpoint URL:

GET https://callback_url/webhooks?
  hub.mode=subscribe&
  hub.challenge=1120110039&
  hub.verify_token=meatyhamhock

My code in 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

But I have this error:

The URL couldn't be validated. Response does not match challenge, expected value="1120110039", received="\u003C!DOCTYPE html>\n\u003Chtm..."

I tried JsonResponse, HttpResponse, and redirect but not work

mostafa
  • 188
  • 2
  • 10
  • What error do you have when you try with `return HttpResponse(challenge)` ? – Tiket_dev Jan 31 '22 at 16:38
  • @Tiket_dev I got this error: The URL couldn't be validated. Response does not match challenge, expected value="1120110039", received="\u003C!DOCTYPE html>\n\u003Chtm..." – mostafa Feb 28 '22 at 11:12
  • I added `content_type='text/plain'` in the `Response` and solved it: `return HttpResponse(challenge, content_type='text/plain')` @Tiket_dev – mostafa Feb 28 '22 at 12:03

1 Answers1

0

I finally found the solution to the problem :)

I added content_type='text/plain' in the Response:

return HttpResponse(challenge, content_type='text/plain')

And Facebook verified my callback URL

mostafa
  • 188
  • 2
  • 10