如何使用 python-instagram 接收实时 Instagram 更新?
How to receive RealTime Instagram update using python-instagram?
我只是想知道如何接收 RealTime Update
来自 <a href="https://github.com/Instagram/python-instagram" rel="nofollow">python-instagram</a>
的更新
它实际上是一个 Flask 应用程序,托管在 Google 云 VM 中。到目前为止,一切都很好。我可以订阅特定的 tag
或 user
。我认为 instagram post 更新了我的服务器。
173.252.105.114 - - [19/Oct/2015:01:40:52 -0400] "POST /hook/instagram HTTP/1.1" 301 517 "-" "Python-httplib2/0.8 (gzip)"
173.252.108.115 - - [19/Oct/2015:01:40:53 -0400] "POST /hook/instagram HTTP/1.1" 301 517 "-" "Python-httplib2/0.8 (gzip)"
173.252.108.119 - - [19/Oct/2015:01:41:31 -0400] "POST /hook/instagram HTTP/1.1" 301 517 "-" "Python-httplib2/0.8 (gzip)"
173.252.113.116 - - [19/Oct/2015:01:41:41 -0400] "POST /hook/instagram HTTP/1.1" 301 517 "-" "Python-httplib2/0.8 (gzip)"
所以我想使用反应器是最好的接收方式,我做了类似的事情....
""" Hook for real time update """
def process_tag_update(update):
new = RealUpdate(update['subscription_id'], updata['object_id'], update['object'])
db.session.add(new)
db.session.commit()
print 'Received a push: '
reactor = subscriptions.SubscriptionsReactor()
reactor.register_callback(subscriptions.SubscriptionType.TAG, process_tag_update)
挂钩url处理....
@app.route('/hook/instagram/',methods=['GET', 'POST'])
def hook_instagram():
if request.method == 'POST':
# 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'
else:
hub_challenge = request.args.get('hub.challenge')
return '{}'.format(hub_challenge)
但我不知道这是不是正确的方法...我不知道 process_tag_update(update)
会产生什么,因为...
- 我无法打印
- 我无法调试
所以有没有人遇到类似的问题..?如何克服这个。?另外,如果您有任何想法可以实现,请告诉我..
问题是 301
重定向。您必须确保您的实时回调 URL 以 /
结束
例如:- /hook/instagram/
我只是想知道如何接收 RealTime Update
来自 <a href="https://github.com/Instagram/python-instagram" rel="nofollow">python-instagram</a>
它实际上是一个 Flask 应用程序,托管在 Google 云 VM 中。到目前为止,一切都很好。我可以订阅特定的 tag
或 user
。我认为 instagram post 更新了我的服务器。
173.252.105.114 - - [19/Oct/2015:01:40:52 -0400] "POST /hook/instagram HTTP/1.1" 301 517 "-" "Python-httplib2/0.8 (gzip)"
173.252.108.115 - - [19/Oct/2015:01:40:53 -0400] "POST /hook/instagram HTTP/1.1" 301 517 "-" "Python-httplib2/0.8 (gzip)"
173.252.108.119 - - [19/Oct/2015:01:41:31 -0400] "POST /hook/instagram HTTP/1.1" 301 517 "-" "Python-httplib2/0.8 (gzip)"
173.252.113.116 - - [19/Oct/2015:01:41:41 -0400] "POST /hook/instagram HTTP/1.1" 301 517 "-" "Python-httplib2/0.8 (gzip)"
所以我想使用反应器是最好的接收方式,我做了类似的事情....
""" Hook for real time update """
def process_tag_update(update):
new = RealUpdate(update['subscription_id'], updata['object_id'], update['object'])
db.session.add(new)
db.session.commit()
print 'Received a push: '
reactor = subscriptions.SubscriptionsReactor()
reactor.register_callback(subscriptions.SubscriptionType.TAG, process_tag_update)
挂钩url处理....
@app.route('/hook/instagram/',methods=['GET', 'POST'])
def hook_instagram():
if request.method == 'POST':
# 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'
else:
hub_challenge = request.args.get('hub.challenge')
return '{}'.format(hub_challenge)
但我不知道这是不是正确的方法...我不知道 process_tag_update(update)
会产生什么,因为...
- 我无法打印
- 我无法调试
所以有没有人遇到类似的问题..?如何克服这个。?另外,如果您有任何想法可以实现,请告诉我..
问题是 301
重定向。您必须确保您的实时回调 URL 以 /
例如:- /hook/instagram/