我在注册我的Twitter网络挂钩时遇到问题。该请求已到达webhook(我可以在日志中看到它),我不断收到此返回信息:
"code":214,"message":"Webhook URL does not meet the requirements. Invalid CRC token or json response format."
code.py
import base64
import hashlib
import hmac
import json
def get(self, request):
crc_token = request.GET.get('crc_token')
consumer_secret = "xxxxxxxx"
sha256_hash_digest = hmac.new(
consumer_secret.encode('utf-8'), msg=crc_token.encode('utf-8'),
digestmod=hashlib.sha256).digest()
response = {
'response_token': 'sha256=' + base64.b64encode(sha256_hash_digest).decode('utf-8'),
'response_code': status.HTTP_200_OK
}
return HttpResponse(response)
我在这里做错了什么?
嗯,我做到了。只需将响应变量转储到json中即可。
return HttpResponse(json.dumps(response))