【问题标题】:Python parsing Instagram api JSON responsePython解析Instagram api JSON响应
【发布时间】: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


    【解决方案1】:

    我发现 response['data'][0]['images']['low_resolution']['url'] 会让你在 json 中达到低分辨率。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-11
      • 2021-12-25
      • 1970-01-01
      • 2019-02-27
      • 2022-01-12
      • 2016-11-15
      • 2017-05-08
      • 1970-01-01
      相关资源
      最近更新 更多