A
A
AlexaAioGram2021-09-10 18:09:14
Bots
AlexaAioGram, 2021-09-10 18:09:14

How to parse the name and VK user ID from a link to his profile?

I have a telegram bot in which it is necessary that when you insert a link to a user in VK, you receive his name and user ID. There is no information on this issue on the Internet, only ways to parse VK groups, but I don’t need it. I would be glad if someone showed or explained how to parse such data.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WolfInChains, 2021-09-10
@AlexaAioGram

If the link is https://vk.com/id663629411 or https://vk.com/innkvi

link_string = "https://vk.com/id663629411"
user = link_string.split("/")[-1].replace("id", "")

Just keep in mind that the custom link can also contain characters id, so add an extra check.
Next, make a request to the api, passing userfrom the code above to the user_ids
https://vk.com/dev/users.get parameter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question