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