0

我一直在尝试为我的应用程序设置订阅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安全组中添加权限?

在此先感谢您的帮助!

回答

2

答:

的Facebook事先不通知发送多个请求的问题,在烧瓶上开发服务器这些请求没有被处理的方式,因此超时的端点。我启动了一个有几名工作人员的gunicorn服务器来测试该理论,事实证明这是真实的,因为我现在已经成功进行了订阅验证。其他任何人具有这一问题烧瓶中:

$ sudo pip install gunicorn 
$ which gunicorn 
/usr/local/bin/gunicorn 


# fire up your endpoint with a few gunicorn workers to handle the load 
# facebook tests our endpoint with (we will use 4 workers on port 5000) 
# my_app is your_app_name.py without the .py part  

$ /usr/local/bin/gunicorn -w 4 -b my-local-ipv4-ip:5000 my_app:app 
0

https://graph.facebook.com/ {0} /订阅” .format(FB_CLIENT_ID)

是用于通过GET方法获取当前订阅


要订阅新订阅,您可以尝试:

https://graph.facebook.com/ {0} /”。format(FB_CLIENT_ID)

通过POST方法---导入:不包括订阅最后url