2015-08-24 27 views
3

我測試用Python和瓶的Instagram的實時API和我每次從Instagram的服務器這樣的響應:Instagram的實時API不能看到我的服務器

{ 
    "meta":{ 
     "error_type":"APISubscriptionError", 
     "code":400, 
     "error_message":"Unable to reach callback URL \"http:\/\/my_callback_url:8543\/instagram\"." 
    } 
} 

請求:

curl -F 'client_id=my_client_id...' \ 
    -F 'client_secret=my_client_secret...' \ 
    -F 'object=tag' \ 
    -F 'aspect=media' \ 
    -F 'object_id=fox' \ 
    -F 'callback_url=http://my_callback_url:8543/instagram' \ 
    https://api.instagram.com/v1/subscriptions/ 

這是瓶服務器的代碼:

from flask import Flask 
from flask import request 

from instagram import subscriptions 

app = Flask(__name__) 

CLIENT_ID = "my_client_id..." 
CLIENT_SECRET = "my_client_secret..." 


def process_tag_update(update): 
    print 'Received a push: ', update 

reactor = subscriptions.SubscriptionsReactor() 
reactor.register_callback(subscriptions.SubscriptionType.TAG, process_tag_update) 


@app.route('/instagram', methods=['GET']) 
def handshake(): 
    # GET method is used when validating the endpoint as per the Pubsubhubub protocol 
    mode = request.values.get('hub.mode') 
    challenge = request.values.get('hub.challenge') 
    verify_token = request.values.get('hub.verify_token') 
    if challenge: 
     return challenge 
    return 'It is not a valid challenge' 

@app.route('/instagram', methods=['POST']) 
def callback(): 
    # POST event is used to for the events notifications 
    x_hub_signature = request.headers.get('X-Hub-Signature') 
    raw_response = request.data 
    try: 
     reactor.process(CLIENT_SECRET, raw_response, x_hub_signature) 
    except subscriptions.SubscriptionVerifyError: 
     print 'Signature mismatch' 
    return 'done' 

def server(): 
    """ Main server, will allow us to make it wsgi'able """ 
    app.run(host='0.0.0.0', port=8543, debug=True) 


if __name__ == '__main__': 
    server() 

該機有一個公網IP和端口爲鄰筆爲每個人。我可以從其他網絡獲取網址。

爲什麼Instagram無法訪問我的網址?有黑名單或類似的東西嗎?


更新1

我有一些框架和WSGI服務器(Django中,燒瓶中,Node.js的,Gunicorn,阿帕奇)和GET/POST端點不同的響應,測試的相同碼我總是得到相同的400錯誤信息。

此外,我已經檢查了Wireshark網絡接口中收到的軟件包,並通過來自任何網絡的呼叫獲得預期的結果。但是我在訂閱請求時沒有收到任何包裹。

所以...這是一個錯誤?出於某種原因,可能是我的IP在任何黑名單中?

+1

雖然有同樣的問題,但還沒有找到任何解決方案。有時(很少)它有效。大部分時間我都會遇到同樣的錯誤 – Joel

回答

0

我完全一樣。它工作時,我不小心重新啓動路由器,獲得不同的IP。它似乎確實可能是一個知識產權問題,在這種情況下Unable to reach callback URL...並不是真的有用。

0

我同意,有大量的AWS服務器回答該API,有些不起作用。 Ping api.instagram.com,你會看到你爲該域名獲得多個不同的IP。有一個DNS循環,你不會每次都到達同一臺服務器。

我找到了一個服務器(IP:52.6.133.72),它似乎在爲訂閱工作,並已配置我的服務器使用該服務器(通過編輯/ etc/hosts文件)。不是一個可靠的解決方案...但它的工作。

相關問題