Answer the question
In order to leave comments, you need to log in
Wall.post and how to add a message to the user?
Good afternoon, the topic is hackneyed, but nevertheless.
1. Created a Standalone application
2. Created an application Website
3. Created a simple JS class that authorizes and posts on the wall when clicking on the buttons:
function Vkontakte() {
function init() {
VK.init({
apiId: 4****8
});
VK.Auth.getLoginStatus(authInfo);
}
function authInfo(response) {
if (response.session) {
console.log('user: ' + response.session.mid);
} else {
console.log('not auth');
}
}
function login(e) {
e.preventDefault();
VK.Auth.login(function(response) {
if (response.session) {
console.log('Пользователь успешно авторизовался');
if (response.settings) {
console.log(response.settings);
}
} else {
console.log('Пользователь нажал кнопку Отмена в окне авторизации');
}
}, 8192 /*Доступ к обычным и расширенным методам работы со стеной. */);
}
function logout(e) {
e.preventDefault();
VK.Auth.logout(function() {
window.location = 'http://localhost/';
});
}
function wallPost() {
VK.Api.call('wall.post', {message: "Привет, это тестовое сообщение"},
function(r) {
});
}
return {
init: init,
login: login,
logout: logout,
wallPost: wallPost
};
}
// Вызов
(function($) {
$(function() {
var vkontakte = Vkontakte();
vkontakte.init();
$(document).on('click', '#vkontakte_login', vkontakte.login);
$(document).on('click', '#vkontakte_logout', vkontakte.logout);
$(document).on('click', '#vkontakte_wall_post', vkontakte.wallPost);
});
})(jQuery);
<script src="//vk.com/js/api/openapi.js"></script>
<script src="/js/vkontakte.authorize.js"></script>
<div>
<img src="/img/vk.png" id="vkontakte_login" ><br>
<a href="" id="vkontakte_wall_post">Запостить ВКонтакте</a><br>
<a href="" id="vkontakte_logout">Выйти из ВКонтакте</a>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question