gpt4 book ai didi

python - Instagram 实时 API 看不到我的服务器

转载 作者:行者123 更新时间:2023-11-28 19:17:13 25 4
gpt4 key购买 nike

我正在使用 Python 和 Flask 测试 Instagram 实时 API,每次我都会收到来自 Instagram 服务器的响应:

{  
"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/

这是 Flask 服务器的代码:

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()

这台机器有一个公共(public) IP,端口对所有人开放。我可以从其他网络访问该 url。

为什么 Instagram 无法访问我的网址?有黑名单之类的吗?


更新 1

我用一些框架和 WSGI 服务器(Django、Flask、Node.js、Gunicorn、Apache)和 GET/POST 端点中的不同响应测试了相同的代码,我总是得到相同的 400 错误消息。

此外,我还使用 Wireshark 检查了在我的网络接口(interface)中接收到的数据包,并且我通过来自任何网络的调用获得了预期的结果。但是当我发出订阅请求时,我没有收到任何包裹。

所以...这是一个错误吗?出于某种原因,我的 IP 可能在任何黑名单中吗?

最佳答案

我的完全一样。当我不小心重新启动路由器时,它起作用了,得到了一个不同的 IP。看起来这确实可能是一个 IP 问题,Unable to reach callback URL... 在这种情况下并不是很有帮助。

关于python - Instagram 实时 API 看不到我的服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32180427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com