аватар question@mail.ru · 01.01.1970 03:00

Posting in VK via vk.api - python

There was a need for the development of a script for posting in the community (group) of the site vk.com pictures. I realized the sending of a simple message (textual) and how to do with Attacment, I can’t understand the good people.

and yes the picture will be presented in the form of

 #/DEV/USR/ENV Python3   #-*-coding: utf-8-*-   Import  vkmy_app_id =  5484091  user_login =  user_password = ' 'password'  sation = vk.authSession (spope =  'vel ", app_id = my_app_id, user_login = user_login, user_password = user_password) vk.api.access_token =  "" 40d8BEAEBFDB3815EF279032BB6C8B3A1374EE0D6704882064FA696866666666666666666666666666666666666666666666666666666666cb3bac7440 " api = vk.api (session) api.wall.post (Owner_id =  '-122263284' , message =  "" just text ... "" ) r  
аватар answer@mail.ru · 01.01.1970 03:00

Try the script first on your page (specify Owner_id = None ). Then on the page of another user. As far as I remember, in groups of VK Owner_id they differ from the user & ndash; Their ID is written with a minus:

   import  vk_api  import  Sys  Import  radom # The script puts pictures on the wall of the user vk.com    def   vk_auth  ( login, password ):  vk = vk_apapi (login, password)   try :  vk.authorization () # authorized    experept  vk_api.authorizationerror  as  error_msg: : : :   print  (error_msg) # In the event of an error, we will display the message   Sysit ()   retu  vk  login =  '' ' password = ' ''  owner_id = "" ""  ''    if  __name__ ==  '' __ main __ ':  # authorize   vk = vk_auth (login, password)  # list with links to pictures   hrefs = [  'https://danbour.donmai.us/data/sample/--Saber-nd-saber-alter-fate-stay-night-an D-Fate-Series-Drawn-by-Goldengear870-Sample-5C666A91632C80384FD9A1E8C43B5FD7.jpg '  ]    random.shuffle (hrefs)  # adding to the user wall   # if you do not specify Owner_id, messages to yourself to the wall It fits    for  href  in  hrefs:  rs = vk.method ( '' 'ipan>, {  'Owner_id' : Owner_id,   'message' :  '' hey! ',  ' Attachments' : href, })   print  (RS)     

if the VK server did not pick up the picture and did not display it in the post, then it will be necessary to pour it on their server first. Here you need to use the methods: Photos.getwalluploadserver and Photos.savewallphoto

Example:

   Def   send_Method  ( methad, data =  none  ):   import  logger  Import  time logger.debug ( 'Launching %S with these: %s. ', method, Data)  rs = vk.method (Method, Data)  logger.debug (' response: "" %s "',  str  (RS) .encode ())  time.sleep ( 0.5 )   retu  rs # the way to picture  file_name = ... rs = Send_MetHod ( 'Сotos.getwalluploadserver' ) upload_url = RS [ 'upload_url' ] rs = redists.post (upload_url, files = { 'epan ":  open  (File_name,  'rt' )}) rs = json.loads (rs.text) rs = send_method ( 'Сotos.savewallphoto' , { 'Photo' : rs [ 'photo' ],  'server' :  'server' ],  'hash' : rs [ 'hash' ]}})  # attachments in `vk.method ('posta>  attachMens =  'Photo {} {}' .  format  (Owner_id, RS [ 0 ] [ 'Id' ])                                       

Latest

Similar