如何使用python-instagram接收RealTime Instagram更新?

时间:2015-10-19 05:48:04

标签: python flask instagram

我只是想知道如何从RealTime Update

接收python-instagram更新

它实际上是Flask应用程序并托管在Google Cloud VM中。到现在为止还挺好。我可以订阅特定的taguser。我认为Instagram将更新发布到我的服务器上。

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)

Hook url handling ....

@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)会发生什么感到失明,因为...... {/ p>

  1. 我无法打印
  2. 我无法调试
  3. 那么是否有人遇到类似的问题..?如何克服这一点。如果您有任何想法,请告诉我..

1 个答案:

答案 0 :(得分:1)

问题是301重定向。您必须确保实时回调网址以/

结尾

例如: - /hook/instagram/