Last active
July 17, 2018 14:37
-
-
Save LB-Digital/9976daa2f88311d28b8c32a186660ba3 to your computer and use it in GitHub Desktop.
Basic usage of the Mojang API
This file contains hidden or 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