我创建了一个Flask应用,其端点可用于Dropbox webhooks。 Dropbox Webhook是一项服务,当我们的Dropbox文件夹中发生某些事件(例如上传文件)时,它将调用我们定义的API端点。我的应用程序的配置如下图所示,清楚地表明已启用了Webhook URI,即Dropbox Webhook的质询URI正常工作(此处隐藏了API_KEY,API_SECRET和app.secret_key)。
接下来,您可以看到我的flask应用程序的代码。问题是我希望每次将文件上传到我的Dropbox文件夹时都会触发/ webhook POST调用,但从未发生。您知道解决此问题的正确方法吗?谢谢。
# App key and secret from the App console (dropbox.com/developers/apps)
APP_KEY = "XXXXXXXXXXXXX"
APP_SECRET = "YYYYYYYYYYYYY"
app = Flask(__name__)
app.debug = True
# A random secret used by Flask to encrypt session data cookies
app.secret_key = "zzzzzzzzzzzzz"
def process_user(account):
print("Yeahhhhh")
@app.route('/webhook', methods=['GET'])
def challenge():
'''Respond to the webhook challenge (GET request) by echoing back the challenge parameter.'''
resp = Response(request.args.get('challenge'))
resp.headers['Content-Type'] = 'text/plain'
resp.headers['X-Content-Type-Options'] = 'nosniff'
return resp
@app.route('/webhook', methods=['POST'])
def webhook():
'''Receive a list of changed user IDs from Dropbox and process each.'''
# Make sure this is a valid request from Dropbox
signature = request.headers.get('X-Dropbox-Signature').encode("utf-8")
if not hmac.compare_digest(signature, hmac.new(APP_SECRET, request.data, sha256).hexdigest()):
abort(403)
for account in json.loads(request.data)['list_folder']['accounts']:
threading.Thread(target=process_user, args=(account,)).start()
return ''
if __name__=='__main__':
app.run(host='0.0.0.0')
答案 0 :(得分:0)
要检查您是否没有从Dropbox收到预期的webhook notification请求,需要检查一些事情。确保您拥有: