First partIn 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'
- In the act parameter we pass the necessary action - either 'post' to publish the message, or 'delete' to delete it. Moreover, when deleting, you must also pass the parameter 'post', which contains the page id and the message sequence number on the wall, for example, 11111_32;
- The facebook_export and status_export parameters are used to export to Facebook and Twitter services, if they are linked to the page;
- The hash parameter is already familiar to us, it can be found when opening a page or group in a block with parameters called post_hash;
- It is worth noting that the note_title parameter is omitted, that is, no notes will be created, instead your entry will be cut if it exceeds the allowable size;
- In to_id it is worth passing your official page id or group with a minus sign in front, for example, '-11111';
- It remains to consider the media and media_type, in the first you should pass an internal link to the desired object, and in the second its type. For example, media => '1111_1213232213', media_type => 'photo'. In this case, the specified photo will be attached to the record. The type can also be 'audio', 'video'. If you pass the type 'share', and in 'media' a pointer to a photo, then in the message link this photo will be in the tooltip. Just need not forget to add three more parameters known to us for the link - url, title and description
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'
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