Reputation: 151
I would like to extract the data from MARVEL DEVELOPER by API code and analyze it (using R).
I got the following url from MARVEL website: http://gateway.marvel.com:80/v1/public/characters?apikey=f389fcb49ad574e10ca570867f4bfa43
I used httr package to collect the data:
install.packages("httr")
library(httr)
> url <- GET("http://gateway.marvel.com:80/v1/public/characters?orderBy=name&limit=100&apikey=f389fcb49ad574e10ca570867f4bfa43")
> content(url)
$code
[1] "MissingParameter"
$message
[1] "You must provide a hash."
I want to extract all this data to R. What should I do/read?
Thanks.
Upvotes: 15
Views: 17964
Reputation: 61
You need to have the following combination ts+ your private key+ your public key
Please check the below example from MARVEL:
For example, a user with a public key of "1234" and a private key of "abcd" could construct a valid call as follows: http://gateway.marvel.com/v1/public/comics?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150 (the hash value is the md5 digest of 1abcd1234)
ts -1 private key- abcd public key - 1234
Upvotes: 6
Reputation: 7232
You have to provide ts (timestamp) and hash parameter. Hash is (according to documentation) = md5(ts+privateKey+publicKey)
You can compute md5 with:
library(digest)
hash <- digest(paste0(ts, privateKey, publicKey), algo="md5")
Server-side applications must pass two parameters in addition to the apikey parameter:
ts - a timestamp (or other long string which can change on a request-by-request basis)
hash - a md5 digest of the ts parameter, your private key and your public
key (e.g. md5(ts+privateKey+publicKey) For example, a user with a public key of "1234" and a private key of "abcd" could construct a valid call as follows:
http://gateway.marvel.com/v1/public/comics?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150 (the hash value is the md5 digest of 1abcd1234)
Upvotes: 15
Reputation: 8494
The hash described in other answers is only when you're using your private key.
The public key can be used in the way you're attempting by adding a referrer:
curl --referer localhost http://gateway.marvel.com:80/v1/public/characters?apikey=f389fcb49ad574e10ca570867f4bfa43
I don't know R
so a curl
request will have to do.
In your developer account you can list the allowed referrers. I have localhost but your's can be whatever...
Upvotes: 4