File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+
3+ """
4+ @author: Kirill Python
5+ @contact: https://vk.com/python273
6+ """
7+
8+ import vk_api
9+
10+
11+ def captcha_handler (captcha ):
12+ key = input ("Enter Captcha {0}: " .format (captcha .get_url ())).strip ()
13+
14+ # Пробуем снова отправить запрос с капчей
15+ return captcha .try_again (key )
16+
17+
18+ def main ():
19+ """ Пример: обработка капчи """
20+
21+ login , password = 'python@vk.com' , 'mypassword'
22+ vk = vk_api .VkApi (
23+ login , password ,
24+ captcha_handler = captcha_handler # function for handle captcha
25+ )
26+
27+ try :
28+ vk .authorization ()
29+ except vk_api .AuthorizationError as error_msg :
30+ print (error_msg )
31+ return
32+
33+ # some code
34+ # ...
35+
36+ if __name__ == '__main__' :
37+ main ()
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+
3+ """
4+ @author: Kirill Python
5+ @contact: https://vk.com/python273
6+ """
7+
8+ import vk_api
9+
10+
11+ def main ():
12+ """ Пример: получение всех постов со стены """
13+
14+ login , password = 'python@vk.com' , 'mypassword'
15+ vk = vk_api .VkApi (login , password )
16+
17+ try :
18+ vk .authorization ()
19+ except vk_api .AuthorizationError as error_msg :
20+ print (error_msg )
21+ return
22+
23+ tools = vk_api .VkTools (vk )
24+
25+ wall = tools .get_all ('wall.get' , 100 , {'owner_id' : '183433824' })
26+ print ('Posts count:' , wall ['count' ])
27+
28+ if wall ['count' ]:
29+ print ('First post:' , wall ['items' ][0 ], '\n ' )
30+
31+ if wall ['count' ] > 1 :
32+ print ('Last post:' , wall ['items' ][- 1 ])
33+
34+ if __name__ == '__main__' :
35+ main ()
Original file line number Diff line number Diff line change 22
33"""
44@author: Kirill Python
5- @contact: http://vk.com/python273
6- @license Apache License, Version 2.0, see LICENSE file
7-
8- Copyright (C) 2014
5+ @contact: https://vk.com/python273
96"""
107
118import vk_api
@@ -20,17 +17,16 @@ def main():
2017 try :
2118 vk .authorization ()
2219 except vk_api .AuthorizationError as error_msg :
23- print (error_msg ) # В случае ошибки выведем сообщение
24- return # и выйдем
20+ print (error_msg )
21+ return
2522
2623 values = {
2724 'count' : 1 # Получаем только один пост
2825 }
2926 response = vk .method ('wall.get' , values ) # Используем метод wall.get
3027
3128 if response ['items' ]:
32- # Печатаем текст последнего поста со стены
33- print (response ['items' ][0 ]['text' ])
29+ print (response ['items' ][0 ])
3430
3531if __name__ == '__main__' :
3632 main ()
Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+
3+ """
4+ @author: Kirill Python
5+ @contact: https://vk.com/python273
6+ """
7+
8+ import vk_api
9+
10+
11+ def main ():
12+ """ Пример: загрузка фото """
13+
14+ login , password = 'python@vk.com' , 'mypassword'
15+ vk = vk_api .VkApi (login , password )
16+
17+ try :
18+ vk .authorization ()
19+ except vk_api .AuthorizationError as error_msg :
20+ print (error_msg )
21+ return
22+
23+ upload = vk_api .VkUpload (vk )
24+ photo = upload .photo ( # Подставте свои данные
25+ 'D:/downloads/tube.jpg' ,
26+ album_id = 200851098 ,
27+ group_id = 74030368
28+ )
29+
30+ vk_url = 'https://vk.com/photo{}_{}' .format (
31+ photo [0 ]['owner_id' ], photo [0 ]['id' ]
32+ )
33+
34+ print (photo , '\n Link: ' , vk_url )
35+
36+ if __name__ == '__main__' :
37+ main ()
You can’t perform that action at this time.
0 commit comments