如何从Instagrapi列表响应中获取某些数据
因此,我正在研究一些代码,以拉出喜欢Instagram上帖子的人的照片。我正在为API系统使用Instagrapi,但是使用api.media_likers
返回所需信息列表。由于某些原因,它将其返回typeError:'userShort'对象无法订阅
。我不确定该怎么做,因为这里的代码:
from instagrapi import Client
insta_user = ""
insta_pass = ""
api = Client() #logs in
api.login(insta_user, insta_pass) #logs in
url = input("Please enter the url to the populer photo: ")
populer_photo_id = api.media_pk_from_url(url) # gets media id from url given from user
print(f"got media id ==> {populer_photo_id}")
get_likes = api.media_info(populer_photo_id).dict() # gets number of likes
likes = get_likes['like_count'] # gets number of likes
likers_res = api.media_likers(populer_photo_id) # gets the people who have liked said post (returns in list)
print(list((object['username'] for object in likers_res)))
应该从列表中返回用户名,而是返回
Please enter the url to the populer photo: https://www.instagram.com/p/xxxxxxxxxx/
got media id ==> xxxxxxxxxxxxxxxx
Traceback (most recent call last):
File "c:\Users\gagem\Documents\Pr0j3cts\insta-promo\testing-api-file.py", line 43, in <module>
print(list((object['username'] for object in likers_res)))
File "c:\Users\gagem\Documents\Pr0j3cts\insta-promo\testing-api-file.py", line 43, in <genexpr>
print(list((object['username'] for object in likers_res)))
TypeError: 'UserShort' object is not subscriptable
so I'm working on some code to pull the pictures of people who have liked a post on instagram. i'm using instagrapi for the api system, but when using api.media_likers
which returns a list of needed info. for some reason it returns it with TypeError: 'UserShort' object is not subscriptable
. Im not sure what to do because the code here:
from instagrapi import Client
insta_user = ""
insta_pass = ""
api = Client() #logs in
api.login(insta_user, insta_pass) #logs in
url = input("Please enter the url to the populer photo: ")
populer_photo_id = api.media_pk_from_url(url) # gets media id from url given from user
print(f"got media id ==> {populer_photo_id}")
get_likes = api.media_info(populer_photo_id).dict() # gets number of likes
likes = get_likes['like_count'] # gets number of likes
likers_res = api.media_likers(populer_photo_id) # gets the people who have liked said post (returns in list)
print(list((object['username'] for object in likers_res)))
This is supposed to return the username from the list but instead returns
Please enter the url to the populer photo: https://www.instagram.com/p/xxxxxxxxxx/
got media id ==> xxxxxxxxxxxxxxxx
Traceback (most recent call last):
File "c:\Users\gagem\Documents\Pr0j3cts\insta-promo\testing-api-file.py", line 43, in <module>
print(list((object['username'] for object in likers_res)))
File "c:\Users\gagem\Documents\Pr0j3cts\insta-promo\testing-api-file.py", line 43, in <genexpr>
print(list((object['username'] for object in likers_res)))
TypeError: 'UserShort' object is not subscriptable
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要更改
为
you just need to change
into