Answer the question
In order to leave comments, you need to log in
How to send a post to the wall of the Vkontakte group with a picture using the VK API JavaScript?
Good evening!
Tell me, please, how to organize the sending of a post (text) with a picture to your Vkontakte group? Yes, the principle itself is perfectly described here . The question is in a working example, which I can’t find / write in any way.
With sending text (in JS) - sort of figured it out. index.html
:
<script src="//vk.com/js/api/xd_connection.js?2" type="text/javascript"></script>
<script src="//vk.com/js/api/openapi.js" type="text/javascript"></script>
<button id="send_tour_button">Отправить в группу Вконтакте</button>
<script>
// VK Init.
VK.init({
apiId: ID_APP
});
// Сама функция.
function WallPost(send_data) {
VK.api('wall.post', {owner_id: '-GROUP_ID', message: send_data}, function(data) {
if (data.response) alert('Успешно опубликовано в группе!');
});
}
// Send.
document.getElementById('send_tour_button').onclick = function() {
WallPost('Тестовое сообщение!');
}
</script>
index.html
. Answer the question
In order to leave comments, you need to log in
Specifically, you won’t be able to upload files via JavaScript because the VK API does not support CORS.
Suppose you have a form on your site where textarea and input[type=file]. You want to make sure that when submitting the form, all this goodness is fasted on VKontakte on the wall of your group. The steps will be like this:
VK.api('wall.post', {
owner_id: '-GROUP_ID',
message: send_data,
attachments: 'photo' + photo_id // photo_id - это ID изображения
}, function(data) {
if (data.response) alert('Успешно опубликовано в группе!');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question