D
D
discognate2015-10-25 12:02:28
PHP
discognate, 2015-10-25 12:02:28

Get user id VK?

I wrote a topic here, Is it possible to get the url of the vk avatars + full name?
but apparently no one understood me, I need to determine the ID of the VK user who came to my site and display his info, full name and profile picture.
There is a code

<?php
$userid = 1;    // йа, йааа
$method = 'users.get';

$url = sprintf( 'https://api.vk.com/method/%s', $method);

$ch = curl_init();
curl_setopt_array( $ch, array(
    CURLOPT_POST    => TRUE,            // это именно POST запрос!
    CURLOPT_RETURNTRANSFER  => TRUE,    // вернуть ответ ВК в переменную
    CURLOPT_SSL_VERIFYPEER  => FALSE,   // не проверять https сертификаты
    CURLOPT_SSL_VERIFYHOST  => FALSE,
    CURLOPT_POSTFIELDS      => array(   // здесь параметры запроса:
        'user_id'   => $userid,
    ),
    CURLOPT_URL             => $url,    // веб адрес запроса
));

$vk_response = curl_exec($ch); // запрос выполняется и всё возвращает в переменную
curl_close( $ch);

if( $result = json_decode( $vk_response)) { // пробуем распаковать JSON 
    printf('<div>Имя: %s<br />Фамилия: %s</div>', // получилось, выводим ответ
        $result->response[0]->first_name,
        $result->response[0]->last_name
    );
    echo 'Вообще, декодированный ответ ВК выглядит целиком вот так::<br /><pre>' . print_r( $result, TRUE) . '</pre>';
} else {  //  JSON не распаковался
    echo 'VK вернул какой-то не JSON совсем:<br /><pre>' . print_r( $vk_response, TRUE) . '</pre>';
}
?>

Actually how to get
$userid = id of the user who came to my site;
Without any extras. windows, keys and applications, is it possible? if not, how using the application ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Grechushnikov, 2015-10-25
@maxyc_webber

There are a lot of ready-made libraries on github. take it and use it

V
Vadim Ardanov, 2015-10-25
@ardanow

Without the knowledge of the user, most likely it will not work.
But there are services, such as socfishing.ru , that can provide data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question