Skip to content

Instantly share code, notes, and snippets.

@joeLepper
Created February 9, 2014 07:24
Show Gist options
  • Save joeLepper/8895586 to your computer and use it in GitHub Desktop.
Save joeLepper/8895586 to your computer and use it in GitHub Desktop.
var request = require('request')
, qs = request('querystring')
, modhash
, cookie;
function postComment () {
var parentId = 't1_cf9k3wa'
, options = {
url : 'https://api.reddit.com/api/comment',
headers : {
'User-Agent' : 'foobot/0.1 by username',
'X-Modhash' : modhash,
'Cookie' : cookie
},
method : 'POST',
body : qs.stringify({
api_type : 'json',
text : 'foobar',
thing_id : parentId
})
};
request(options, function (err, res, body) {
if (err) {
console.log(err);
return;
} else {
console.log('// ------ //');
console.log(res);
console.log(body);
console.log('// ------ //');
}
});
}
function login () {
var options = {
url : 'https://ssl.reddit.com/api/login?api_type=json&user=username&passwd=password&rem=True',
headers : {
'User-Agent' : 'foobot/0.1 by username'
},
method : 'POST'
};
request(options, function (err, res, body) {
if (err) {
console.log(err.json.errors);
return;
} else {
var parsedBody = JSON.parse(body);
console.log('// ------ //');
console.log(parsedBody.json.data.modhash);
console.log(parsedBody.json.data.cookie);
console.log(parsedBody.json.data);
modhash = parsedBody.json.data.modhash;
cookie = parsedBody.json.data.cookie;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment