instagram_private_api
instagram_private_api copied to clipboard
How to get media_id of a user
Please follow the guide below
- Issues submitted without this template format will be ignored.
- Rlease read them carefully and answer completely.
- Do not post screenshots of error messages or code.
- Put an
x
into all the boxes [ ] relevant to your issue (==> [x] no spaces). - Use the Preview tab to see how your issue will actually look like.
- Issues about reverse engineering is out of scope and will be closed without response.
- Any mention of spam-like actions or spam-related tools/libs/etc is strictly not allowed.
Before submitting an issue, make sure you have:
- [x] Updated to the lastest version v1.6.0
- [x] Read the README and docs
- [x] Searched the bugtracker for similar issues including closed ones
- [x] Reviewed the sample code in tests and examples
Which client are you using?
- [x] app (
instagram_private_api/
) - [ ] web (
instagram_web_api/
)
Describe your Question/Issue:
Hello Guys, I'm trying to get a users last post media_id, like this format 2431422900197522665_1985737254
Paste the output of python -V
here: Python 3.8.5
Code:
# Example code that will produce the error reported
from instagram_web_api import Client
sources = ['wofaifada', 'timidakolo', 'auntyshaggi',]
source = random.choice(sources)
user_info = api.username_info(source)
user_id = user_info['user']['pk']
medias = api.user_feed(user_id,max_id=1)
print(medias)
media = medias[user["pk"]['media_id']]
print(media)
Error/Debug Log:
```File "final.py", line 78, in follow
media = medias[user["pk"]['media_id']]
NameError: global name 'user' is not defined
@ping @jwtrhs @AndreaOrru please kindly help me out
You could take the shortcode and convert it into media id
Code:
def shortcode_to_media_id(shortcode):
alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
id = 0
for i in range(0, len(shortcode)):
char = shortcode[i]
id = (id*64) + alp.index(char)
return id