小编har*_*mkv的帖子

Python/Django使用python-instagram(400)APISubscriptionError-无法访问回调URL

以前的工作.然后它偶尔开始工作,直到它完全停止工作.

以下是我的订阅代码:

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
)
Run Code Online (Sandbox Code Playgroud)

以下是我处理来自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"])
Run Code Online (Sandbox Code Playgroud)

以下是我的urls.py …

python django instagram

5
推荐指数
1
解决办法
1159
查看次数

标签 统计

django ×1

instagram ×1

python ×1