我一直在尝试为我的应用程序设置订阅Realtime Updates API,但出现了一些问题。对于初学者来说,这是我不断收到错误:Facebook实时更新订阅Python中的验证
{"error":{"message":"(#2200) callback verification failed: Operation timed out after 6000 milliseconds with 0 bytes received","type":"OAuthException","code":2200}}
我适当地跟着文档和处理HTTP GET和POST Amazon EC2实例配置的烧瓶中的端点。会发生什么事情,我手动点击并终止自己,以调用订阅代码。
curl -i -X GET http://public-ip-of-ec2:5000/subscribe
上面的curl调用一个脚本运行在一个烧瓶应用程序的/订阅我的EC2实例的路线。要使用所需的查询字符串参数(包括我们的access_token,对象,字段,verify_token和callback_url)进行POST,我正在使用python HTTP库requests。
VERIFY_TOKEN = 'my_verify_token'
@app.route('/subscribe')
def subscribe():
global VERIFY_TOKEN
FB_CLIENT_ID = 'my_app_id'
# access_token is sent as a query string parameter
APP_ACCESS_TOKEN = 'my_app_access_token'
# object, fields, callback_url, and verify_token are sent as urllib.urlencode([('param','val')])
CALLBACK_URL = 'http://my-public-ec2-ip:5000/'
payload_url = "https://graph.facebook.com/{0}/subscriptions".format(FB_CLIENT_ID)
payload = {"access_token": APP_ACCESS_TOKEN, "object": "user", "fields": "feed", "verify_token": VERIFY_TOKEN, "callback_url": CALLBACK_URL}
r = requests.post(payload_url, data=payload)
return r.text
@app.route('/', methods=['GET','POST'])
def handle_requests():
global VERIFY_TOKEN
if request.method == 'GET':
mode = request.args.get('hub.mode')
challenge = request.args.get('hub.challenge')
verification = request.args.get('hub.verify_token')
# if we have our verification token back echo the challenge back to facebook
if verification == VERIFY_TOKEN:
return challenge
elif request.method == 'POST':
# do some stuff with the updates
我很困惑,为什么我得到 {“错误”:{“消息”:“(#2200)回调验证失败:操作超时后6000毫秒收到0字节”, “type”:“OAuthException”,“code”:2200}}
因为当我启动我的烧瓶应用程序时,我可以看到来自173.252.110.113的GET请求,这是一个Facebook IP地址。我已经过适当的测试,以确保通过将挑战打印到我的日志进行测试来回显正确的数据。所以代码返回Facebook验证订阅所需的挑战,并且在那一点上订阅应该成功,但前面提到的错误是我所得到的。难道这可能只是一个安全问题,我需要在ec2安全组中添加权限?
在此先感谢您的帮助!