Answer the question
In order to leave comments, you need to log in
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 отдал данные
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);
}
}
};
}
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