Created
December 1, 2018 00:31
-
-
Save Demonly/d94cf22344f44364be5f1df305c3c40c to your computer and use it in GitHub Desktop.
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
function getCharacterItemLevel(name, server) { | |
var data = JSON.parse(getArmoryData(name, server)); | |
return data.items.averageItemLevel; | |
} | |
function getArmoryData(name, server) { | |
var access_token = authorizeClient("[RADICATED]","[RADICATED]"); | |
var response = UrlFetchApp.fetch("https://us.api.blizzard.com/wow/character/"+server+"/"+name+"?fields=items&locale=en_US&access_token="+access_token); | |
var data = JSON.parse(response.getContentText()); | |
return response.getContentText(); | |
} | |
function authorizeClient(client_id, client_secret) { | |
var url = "https://us.battle.net/oauth/token?"; | |
var payload = | |
{ | |
"client_id" : client_id, | |
"client_secret" : client_secret, | |
"grant_type" : "client_credentials", | |
}; | |
var options = | |
{ | |
"method" : "GET", | |
"payload" : payload, | |
"followRedirects" : true, | |
"muteHttpExceptions": true | |
}; | |
var result = UrlFetchApp.fetch(url, options); | |
if (result.getResponseCode() == 200) { | |
var params = JSON.parse(result.getContentText()); | |
return params.access_token; | |
} else { | |
Logger.log(result); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment