Lua 和 API 需要身份验证 (Wordnik)

发布于 2024-12-01 21:49:18 字数 955 浏览 0 评论 0原文

我已经尝试解决这个问题有一段时间了,但我就是做不到。我使用一个程序(CMUD),其中广泛使用 Lua 脚本语言进行数据挖掘。我编写了一些脚本,使用其 API(无需身份验证)从 wunderground.com 收集天气信息,并且对 Urbandictionary.com 进行数据挖掘以获取俚语术语。现在我尝试利用 Wordnik 的 json 解析器返回单词的定义。然而,我对 API 还很陌生,虽然我已经很好地掌握了 Lua,但我仍然是一个新手。因此,我向您求助,寻求我迫切需要的答案。

根据 Wordnik API 文档,验证用户身份的正确方法是使用以下 url:

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

{format} 可以是 xml 或 json,但我更喜欢 json。使用:

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

返回“未经授权”错误。使用:

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

返回 r = 1 和 c = 401。

我完全困惑于如何验证自己的身份并通过我使用的程序通过 Lua 使用 Wordnik 的 API。任何帮助将不胜感激!或者,如果您知道任何返回 json 格式的字典,我也会很感激这些建议!

出于澄清目的:

我希望能够检索单词定义的 json 格式。直接进行 API 调用似乎不起作用,并且似乎确实需要登录(或身份验证)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

太阳公公是暖光 2024-12-08 21:49:18

哎呀,对 esperluette 的回应稍作修正。标准开发人员 API 密钥无法使用“entries”API。请尝试以下操作:

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

请注意,您在 http://developer.wordnik.com/docs 应该可供您使用。您还可以在请求标头中传递 api_key(首选方法)。

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).

七月上 2024-12-08 21:49:18

我不太确定你想在这里做什么——你是想验证 Wordnik 用户的身份,还是想调用定义?您无需通过 API 以 Wordnik 用户身份“登录”即可调用 Wordnik 定义,只需使用您的 API 密钥即可。

如果您只想要定义的 json 结果,您可以尝试这个调用(对于单词“mustard”):

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

您是否玩过developer.wordnik.com/docs?

希望对你有帮助,我对Lua一无所知。 :-)

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. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文