我正在使用python脚本订阅带有特定标记的Instagram图像。我正在使用urllib2发送一个post请求,但是,它返回错误400:
"meta": {
"code": 400,
"error_message": "Invalid response",
"error_type": "APISubscriptionError"
}
原因:不良请求
状态:400
import bottle
from bottle import route, post, run, request, response
from instagram import client, subscriptions
import urllib
import urllib2
import requests, time
bottle.debug(True)
api = client.InstagramAPI(client_id="CLIENTID", client_secret="CLIENTSECRET")
try:
subscription_url = 'https://api.instagram.com/v1/subscriptions'
values = {'client_id' : 'CLIENTID',
'client_secret' : 'CLIENTSECRET',
'verify_token' : 'myVerifyToken',
'object' : 'tag',
'object_id' : 'fluxcapacitor',
'aspect' : 'media',
'callback_url' : 'http://mcfly.ngrok.com/callback' }
data = urllib.urlencode(values)
req = urllib2.Request(subscription_url, data)
response = urllib2.urlopen(req)
except Exception, e:
print e
@route('/callback')
@post('/callback')
def callback():
mode = request.query.get("hub.mode")
challenge = request.query.get("hub.challenge")
verify_token = request.query.get("hub.verify_token")
return challenge
run(host='0.0.0.0', port=8515, reloader=True)
为了进行调试,我在请求标头中添加了其他参数,以复制实际有效的hurl.it的POST请求。
headers = {'Content-type' : 'application/x-www-form-urlencoded',
'Accept' : '*/*',
'Accept-Encoding' : 'gzip, deflate, compress',
'User-Agent' : 'runscope/0.1'}
通过在Hurl.it中发布请求,Instagram API返回状态200.我使用Runscope比较功能来分析POST请求。请求看起来相同,响应不同。