Skip to content

Instantly share code, notes, and snippets.

@lkLeonov
Created April 14, 2017 08:25
Show Gist options
  • Save lkLeonov/7234d1cc36776f4c848e5e5bfee3b111 to your computer and use it in GitHub Desktop.
Save lkLeonov/7234d1cc36776f4c848e5e5bfee3b111 to your computer and use it in GitHub Desktop.
'use strict'
const http = require('http');
const qs = require('querystring');
const TextDecoder = require('text-encoding').TextDecoder;
const PORT = 3000;
// const VK_UID = 50595075;
const VK_REMIXSID = '00796e02caae56926fcd0881bd3b80711c520ad2cf533e0c32522'; // you must be logined to get this
const VK_REQ_OPTIONS = {
al: 1,
part: 1,
section:'updates',
//al_ad: 0,
//from: '-53612095_327137_1491944400_26',
// more: 1,
offset: 10 // offset (in number of friends' updates in current feed)
}
const Server = function(servReq, servRes) {
if (servReq.method == 'GET') {
const postData = qs.stringify(VK_REQ_OPTIONS);
const postReqOptions = {
hostname: 'vk.com',
path: '/al_feed.php?sm_updates',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; ',
'Content-Length': Buffer.byteLength(postData),
'Cookie':'remixsid=' + VK_REMIXSID,
}
};
const postReq = http.request(postReqOptions, (res) => {
console.log('SERVER::POST: ' + postReqOptions.hostname + postReqOptions.path, res.statusCode);
let vkData = new String;
res.on('data', (chunk) => {
let decoder = new TextDecoder('windows-1251');
vkData += decoder.decode(chunk, {
stream: true
});
});
res.on('end', () => {
servRes.setHeader("Content-Type", "application/json; charset=utf-8");
servRes.write(vkData);
servRes.end();
});
});
postReq.write(postData);
postReq.end();
}
}
http.createServer(Server).listen(PORT);
console.log(`SERVER:: Listening on port ${PORT} ...`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment