@app.route('/webhook', methods=['GET'])
def webhook_verify():
print('testing')
# Get all query parameters from the GET request
query_params = app.current_request.query_params
# Log all parameter names and values
logger.info('Query parameters received:')
for param_name, param_value in query_params.items():
print(f'{param_name}: {param_value}')
hub_verify_token = query_params.get('hub.verify_token')
hub_challenge = query_params.get('hub.challenge')
if hub_verify_token == VERIFY_TOKEN:
# Log a successful verification
print('Webhook verification successful')
return str(query_params.get("hub.challenge")), 200 # 200 OK
# Log an unsuccessful verification
print('Webhook verification failed: Wrong verify token')
return {'error': 'Wrong verify token'}, 403 # 403 Forbidden
这是处理 webhook 的代码
然后我在 Facebook 开发者页面验证回调 URL。然后它说
The callback URL or verify token couldn't be validated. Please verify the provided information or try again later.
表明验证token正确,并返回200响应。所以,我很困惑为什么 Facebook 开发者页面上显示错误
我尝试过的: 查看其他 python facebook Messenger 存储库的其他返回响应格式并遵循该格式,但没有运气。
来自
return str(query_params.get("hub.challenge")), 200 # 200 OK
至
return str(query_params.get("hub.challenge"))
事实证明,使用 chalice for facebook webhooks 处理 200 个请求不需要说明。更改后现在可以使用了