Lua and API requiring authentication (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 go开发者_StackOverflow社区tten 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).
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).
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. :-)
精彩评论