Lua y API que requieren autenticación (Wordnik)

I've been trying to figure this out for a while, and I just can't. I use a program (CMUD) in which I utilize the Lua scripting language extensively for data-mining. I've written scripts that gather weather information from wunderground.com using their API (requires no authentication) and I data-mine urbandictionary.com for slang terminology. Now I'm attempting to utilize the json parser of Wordnik to return the definition of words. However, I'm quite new to API, and while I've gotten a good grasp on Lua, I'm still a neophyte here as well. Therefore, I turn to you, seeking the answers I so desperately need.

According to Wordnik API documentation, the proper way to authenticate a user is with the following url:

http://api.wordnik.com/v4/account.{format}/{username}?password={password}

The {format} can be either xml or json, but I prefer json. Using:

print(http.request("http://api.wordnik.com/v4/account.json/username?password=password"))

returns "unauthorized" errors. Using:

r,c = http.request{ url = "http://api.wordnik.com/v4/account.json/username?password=password", headers = {api_key = "MY_API_KEY"}}

returns r = 1 and c = 401.

I'm just utterly confused as to how I can authenticate myself and use Wordnik's API via Lua through the program I use. Any help would be greatly appreciated! Alternatively, if you know of any dictionaries that return json formats, I'll appreciate those suggestions as well!

For clarification purposes:

I want to be able to retrieve the json format of a definition of a word. Doing the direct API call does not seem to work, and seems that it does require logging in (or authenticating).

preguntado el 28 de agosto de 11 a las 04:08

2 Respuestas

Oops, slight correction to the response from esperluette. The "entries" api isn't available to a standard developer API key. Please try this:

http://api.wordnik.com/v4/word.json/mustard/definitions?api_key=YOUR_API_KEY

Note that everything you see in http://developer.wordnik.com/docs should be available for you. You can also pass the api_key in the request headers (preferred method).

Respondido 29 ago 11, 01:08

Oh, I love you for this. Thank you so much! I hadn't found the /definitions?api_key part -- did I overlook it in the documentation? I thought I had scoured everything there! Thanks again! - Josh

Hi Josh, I have to say, I think you're right. We'll get that in the docs ASAP. Apologies for the trouble that might have caused! - fehguy

I'm not exactly sure what you're trying to do here -- are you trying to authenticate a Wordnik user, or are you trying to call definitions? You can call Wordnik definitions without "logging in" as a Wordnik user via the API, just use your API key.

If you just want json results for definitions, you can try this call (for the word 'mustard'):

http://api.wordnik.com/v4/word.json/mustard/entries?api_key=YOUR_API_KEY

Have you played around with developer.wordnik.com/docs?

I hope this is helpful, I know nothing about Lua. :-)

Respondido 28 ago 11, 22:08

I tried your suggestion, and it doesn't work, unfortunately. It keeps returning {"message": "unauthorized", "type": "error"} as the json. I've looked through the documentation, but unfortunately, nothing I've tried seems to work. I'm trying to authenticate the user (me, in this case) so that I can make the API calls, but it's simply not working, and I don't know what I'm missing. Thanks for trying, at least! - Josh

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.