Basic usage of the Mojang API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// INFO: This script currently relies on the 'request' npm module, | |
// however this will change in the near future to become independant. | |
// http://wiki.vg/Mojang_API | |
const MojangAPI = { | |
base: "https://api.mojang.com", | |
getUUID: (username, done)=>{ | |
request(MojangAPI.base + '/users/profiles/minecraft/' + username, (err, response, body)=>{ | |
try{ | |
var uuid = JSON.parse(body).id; | |
return done(null, uuid); | |
} catch(e){ | |
return done(true); // err=true | |
} | |
}); | |
}, | |
getUsername: (uuid, done)=>{ | |
request(MojangAPI.base + '/user/profiles/' + uuid + '/names', (err, response, body)=>{ | |
try{ | |
var username = JSON.parse(body).pop().name; // pop latest name change from array | |
return done(null, username); | |
} catch(e){ | |
return done(true); // err=true | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment