从Instagram API获取所有类型为“image”的媒体(Get all media with type “image” from Instagram API)

编程入门 行业动态 更新时间:2024-10-25 12:16:14
从Instagram API获取所有类型为“image”的媒体(Get all media with type “image” from Instagram API)

我试图从Instagram API获取用户的图像,如下所示:

shop_recent_items, next_ = instagram_api.user_recent_media( user_id=obj.insta_user_id, count=33)

这将返回图像和视频。 我甚至试过这个:

shop_recent_items, next_ = instagram_api.user_recent_media( user_id=obj.insta_user_id, type='image' count=33)

我又得到了图像和视频类型的媒体。

我如何只获得图像?

I am trying to get only images of a user from Instagram API like this:

shop_recent_items, next_ = instagram_api.user_recent_media( user_id=obj.insta_user_id, count=33)

this returns both images and videos. I tried even this:

shop_recent_items, next_ = instagram_api.user_recent_media( user_id=obj.insta_user_id, type='image' count=33)

again I get both image and video type media.

How do I get only images?

最满意答案

查看官方文档 ,它说它可能会返回图像和视频类型的混合。 所以你不可能说你只想要图像。 相反,一旦您检索信息,提取图像。

因此,一旦获得JSON数据,使用for循环,您就可以找到所有图像。 示例代码:

for media in shop_recent_items: try: print media['images'] except KeyEror: continue

如果您可以向我显示shop_recent_items确切响应和内容,我将相应地编辑此示例代码。

Looking at the official documentation, it says it may return a mix of both image and video types. So you cannot possibly say you only want images. Instead, once you retrieve the info, extract images.

So once you get the JSON data, using a for loop, you can find all the images. Sample code:

for media in shop_recent_items: try: print media['images'] except KeyEror: continue

If you could show me exact response and contents of shop_recent_items, I will edit this sample code accordingly.

更多推荐

本文发布于:2023-08-05 07:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428966.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   媒体   Instagram   API   type

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!