Created
March 12, 2016 21:21
-
-
Save tleen/7a686d43b0edc60ba35a to your computer and use it in GitHub Desktop.
Example call to the Marvel API from js client (w/ JQuery)
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
// you will also have to setup the referring domains on your marvel developer portal | |
var PRIV_KEY = "this-should-be-a-long-hash"; | |
var PUBLIC_KEY = "so-should-this"; | |
function getMarvelResponse() { | |
// you need a new ts every request | |
var ts = new Date().getTime(); | |
var hash = CryptoJS.MD5(ts + PRIV_KEY + PUBLIC_KEY).toString(); | |
// the api deals a lot in ids rather than just the strings you want to use | |
var characterId = '1009718'; // wolverine | |
var url = 'http://gateway.marvel.com:80/v1/public/comics'; | |
console.log(url); | |
$.getJSON(url, { | |
ts: ts, | |
apikey: PUBLIC_KEY, | |
hash: hash, | |
characters: characterId | |
}) | |
.done(function(data) { | |
// sort of a long dump you will need to sort through | |
console.log(data); | |
}) | |
.fail(function(err){ | |
// the error codes are listed on the dev site | |
console.log(err); | |
}); | |
}; | |
getMarvelResponse(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Me too, thank you !