B
B
Billy Milligan2013-12-10 23:40:22
PHP
Billy Milligan, 2013-12-10 23:40:22

How to get data using VK API?

I'm trying to register using the VK API, I want the user to click on the button, confirm that he agrees, of course, the registration went through and he was redirected to the main page.

<div id="login_button" onclick="VK.Auth.login(authInfo);">Войти</div>

<script language="javascript">
    VK.init({
        apiId: APP_ID
    });
    function authInfo(response) {
        if (response.session) {
            window.location.replace("https://oauth.vk.com/authorize?client_id=APP_ID&redirect_uri=http://site.ru/test2.php&response_type=code");
        } else {
            alert('not auth');
        }
    }
</script>

test2.php
if(empty($_GET['code'])) {
    echo "это успех!";
} else {
    header("location:https://oauth.vk.com/access_token?client_id=APP_ID&client_secret=APP_SECRET&code=".$_GET['code']."&redirect_uri=http://site.ru/test2.php");
}

I understand something, but not completely, the documentation in particular. Everything goes fine, I get access_token, expires_in, user_id at https://oauth.vk.com. What next to do with these? Pick it up AJAX? but I want to process it all in php, do I really need to do so many shenanigans.
maybe I'm doing something wrong? poke as needed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sasha, 2013-12-11
@madmages

Even I don’t understand, having received an access token, you can already make requests for VK api, what is the actual question?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question