过去的事情是有效的。然后它开始偶尔工作,直到它完全停止工作。
以下是我的订阅代码:
def instagram_realtime_subscribe(event_slug, topic):
api = InstagramAPI(client_id = CLIENT_ID, client_secret = CLIENT_SECRET)
r = api.create_subscription(object = 'tag',
object_id = topic,
aspect = 'media',
callback_url = 'http://<domain>/event/%s/import/instagram/realtime'%(event_slug),
client_id = CLIENT_ID,
client_secret = CLIENT_SECRET
)
以下是我处理来自 instagram 的 GET 和 POST 请求的观点:
def import_instagram_rt(request, slug):
if request.method == "GET":
mode = request.GET.get("hub.mode")
challenge = request.GET.get("hub.challenge")
verify_token = request.GET.get("hub.verify_token")
if challenge:
return HttpResponse(challenge, mimetype='text/html')
else:
return HttpResponse("test", mimetype='text/html')
else:
x_hub_signature=''
if request.META.has_key('HTTP_X_HUB_SIGNATURE'):
x_hub_signature = request.META['HTTP_X_HUB_SIGNATURE']
raw_response = request.raw_post_data
data = simplejson.loads(raw_response)
for update in data:
fetch_data(slug, update["object_id"])
以下是我的 urls.py
url(r'^event/([-\w]+)/import/instagram/realtime$', import_instagram_rt),
这用于精美地工作。但是,两天后它就停止了工作。每当调用订阅函数时,它都会抛出错误:
>>> instagram_realtime_subscribe("cats", "cats")
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/ubuntu/webapps/django-projects/imports/views.py", line 687, in instagram_realtime_subscribe
client_secret = CLIENT_SECRET
File "/home/ubuntu/webapps/django-projects/local/lib/python2.7/site-packages/instagram/bind.py", line 151, in _call
return method.execute()
File "/home/ubuntu/webapps/django-projects/local/lib/python2.7/site-packages/instagram/bind.py", line 143, in execute
content, next = self._do_api_request(url, method, body, headers)
File "/home/ubuntu/webapps/django-projects/local/lib/python2.7/site-packages/instagram/bind.py", line 124, in _do_api_request
raise InstagramAPIError(status_code, content_obj['meta']['error_type'], content_obj['meta']['error_message'])
InstagramAPIError: (400) APISubscriptionError-Unable to reach callback URL "http://<domain>/event/cats/import/instagram/realtime".
我尝试手动点击回调 URL 并得到响应“测试”,这是您对我编写的函数的期望。在调用订阅函数之前,我手动尝试了 requests.get() 到该 url,并返回了 200 响应。
当其他人都可以访问它时,为什么 Instagram 找不到我的回调 url?