【发布时间】:2016-04-08 21:06:41
【问题描述】:
我正在使用 Instagram 开发人员 API 的 User Endpoint 在 python-3.3 中工作,以从我关注的一个人那里获取最近的媒体。
response = requests.get(URL).json()
test = response["data"]
return HttpResponse(test, "text/html")
在我的示例响应中为我提供 data[...] 部分中的内容。
但是,我似乎无法访问比这更深的内容。
例如,
response = requests.get(URL).json()
test = response["data"]
return HttpResponse(test[0], "text/html")
给我下一个键的列表:
"typecreated_timeuserattributionfilterusers_in_photocaptionlikestagslinkimagesiduser_has_likedcmetslocation"
同时:
response = requests.get(URL).json()
test = response["data"]
return HttpResponse(test["images"], "text/html")
给我一个例外:“列表索引必须是整数,而不是 str”
我还可以为每个外观等做:
response = requests.get(URL).json()
test = response["data"]
for test in response["data"]:
for image in test["images"]:
HttpResponse(image["low_resolution"], "text/html")
return HttpResponse(test["images"], "text/html")
等,它将继续返回键名,直到像上面这样给我一个错误“字符串索引必须是整数”。
例如,如果我想访问 data->(first block)->images->low_resolution->url,我应该怎么做?
提前致谢。
【问题讨论】:
标签: json python-3.3 instagram-api