📜 ⬆️ ⬇️

Automatic notification of readers about the news using VKontakte. Part 2

First part

In the first part, we learned how to automatically publish entries on our wall, today we will add blackjack and sluts to add pictures to links automatically. This time I will not give ready-made php functions, as they are described in the first part, and now I will only describe the php files and parameters that we need to pass to them.

After the first part I received a large number of messages, most of which were devoted to what I demonstrated in the article the possibility of publishing on my own wall, and I did not show automatic publication on the wall of the Group or the Official page. Therefore, I will start with what parameters you need to pass.

Official page


You must be a member of the page administrators to be able to post news. Consider we need the parameters that are passed to al_wall.php when publishing a simple message:
act => 'post', 'delete' al => 1 facebook_export => '' status_export => '' friends_only => '' hash => '' message => '' note_title => '' official => '' to_id => '' type => 'all' media => '' media_type => 'photo' 


Alas, but so far I have not found a way to publish a message-photo together with a message-link as it was done on the page Habrahabr VKontakte.
')

Upload photos


In fact, when downloading a picture, the main thing is not to forget about the proxy, and then everything is quite simple. So, to upload a picture, we will use the share.php file, which is intended for publishing external links. Here is an example of POST parameters that need to be passed to it:

 act => a_photo url => image => extra => 

In the url parameter, you pass your link, in the image parameter - a link to the desired image, and you can ignore the extra parameter. I note that if you use CURL, as I did in the last part, then do not forget the following:
 curl_setopt($ch, CURLOPT_REFERER, 'http://vkontakte.ru/share.php'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

We need the second parameter, because after sending a POST request, share.php will redirect the request (by returning 302 errors and passing the Location parameter) to upload.php with the necessary server and the necessary parameters, which I think makes no sense. In turn, upload.php will redirect the request to complete.php, which, depending on the success, will produce either an error or the result we need.

Option with error:
 <script type="text/javascript"> document.domain = location.host.toString().match(/[a-zA-Z]*\.[a-zA-Z]*$/)[0]; parent.onUploadFail(0, ' '); </script> 

This means that most likely your link to the picture is incorrect or invalid. The option we need looks like this:
 <script type="text/javascript"> document.domain = location.host.toString().match(/[a-zA-Z]*\.[a-zA-Z]*$/)[0]; parent.onUploadDone(0, {"user_id":1234567,"photo_id":235889241}); </script> 

Here it is, the very photo_id that needs to be transmitted when placing a photo on the wall, in this case, the full composite id: 1234567_235889241. Just, isn't it?

To get a direct path to the uploaded photo, you need to send a request to al_photo.php, which I haven’t fully understood yet, in particular, it’s not clear what kind of hash it requires to verify the request. If someone understands - tell :).

It is worth noting that you can place a link with a picture in the tooltip not only through al_wall.php as I described above, but also through share.php, for this you need to send the request to share.php again with a lot of parameters. I will put comments where difficulties may arise:
 act: 'a_submit' //  hash: shareHash //   onDomReady,      share.php  ,   window.shareHash title: //   url: //  share_title: //   share_text: //   share_comment: //   image_url: //   ,     onUploadFail photo_owner_id: // id   photo_id: // id,    privacy_note: 0 //    0 privacy_notecomm: 0 //    0 to_status: 1 // 1,    status_export: //     to_note: // ,      1,    

In general, through share.php, you can publish video and audio, upload them to the server through the extra and extra_data parameters, but I don’t see any urgent need for this.

I think that while this is more than enough, when I find a way to combine links and photos in one message, I will write how this can be done. Or I will hope that they will open such functionality for Groups and Official Pages. I note only that if you upload a photo via the VKontakte interface on the Official page, then photo_id will be assigned as '[-id page] _ [number_photo]', and when viewing the photo, the author will be your page or group.

This effect can also be achieved through the script, if the parameters are not transferred to share.php, but directly to upload.php, but in this case we need to know a lot more parameters, including two different hash parameters, so I don’t consider this way has become.

Separate request to ask questions on the topic in the comments, and not through personal mail, because most of the questions are the same and you have to explain the same thing every time :).


UPD : At the request of the comments sketched out a simple class and an example of use.
Take here: github.com/xbreaker/vk.wallpost

Source: https://habr.com/ru/post/115658/


All Articles