M
M
Mark Ivanych2014-08-27 15:20:44
In contact with
Mark Ivanych, 2014-08-27 15:20:44

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>

1. We start authorization: In both applications, in a new window, it is indicated that access to the wall is required, which means everything seems to be OK.
2. Post on the wall: When I click on the "Post VKontakte" button, a window appears in which you need to confirm adding a post to the wall. I click "Add entry", the window disappears, there is nothing on the wall, and the application is removed from VKontakte. I test everything from localhost, respectively, localhost is specified in the base domain, perhaps because of this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question