O
O
Ololosha2282016-04-21 22:48:11
JavaScript
Ololosha228, 2016-04-21 22:48:11

How to make a get request to vk api without a token using javascript?

Good day.
I am writing an HTML / JavaScript application that should analyze the list of pages, groups, likes, etc. to find links with each other (from the list of pages, in the sense that the user clogs)
For this, obviously, you need to contact the vk api, and specifically , I want to access only those methods that do not require a token (anyway, the token is only needed to use private or semi-public information, and I only need to search for public information).
Somehow I picked up variations from stack overflow on how to still send requests to pages.
Basically the idea itself:

function httpGetAsync(theUrl, callback)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            callback(xmlHttp.responseText);
    }
    xmlHttp.open("GET", "https://api.vk.com/method/users.get?id=1", true);
    xmlHttp.send(null);
}
alert(httpGetAsync.callback); // для проверки, что api отдал данные

The result is undefined. I have already tried everything, pasted the link to the "page" into the browser - it works. It means that the request page was made correctly. I'm looking at the XMLHttpRequest documentation - I can't find anything (because I'm really blind, it's really simple). The second day I sit, I understand that autism is from God, but still I can’t find a mistake. Help, for the sake of duct tape, please.
UPD:
I tried to code my own version with the help of Russian documentation xmlhttp:
function vkGetMethod (url, callback) //задаем функцию для удобства
{
    var vkRequest = new getXmlHttp(); //создаем переменную xmlhttp 
    vkRequest.open ('GET', 'https://api.vk.com/method/users.get?id=1', true); //создаем запрос
    vkRequest.send(null); // отправляем с параметром null
    vkRequest.onreadystatechange = function() {  //эта функция -- проверка запроса (если выполнен (4) 
    if (vkRequest.readyState === 4) {            // и ответ сервера есть (200), тогда выводим код страницы (responseText)
        if(vkRequest.status === 200) {
            alert(vkRequest.responseText);
            }
        }
    };
    
}

so what am i doing wrong? maybe there is a way to send a get request to another tool?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nuhena, 2016-04-21
@nuhena

Is cross domain requests allowed in javascript?

G
goshva, 2016-06-20
@goshva

this craft almost works for me (I take public photos from the albums of the group) if this is on your topic - maybe we can put together something normal - javascript.ru/forum/dom-window/63580-vk-api-callba...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question