Yandex API Translator error - 401 API key is invalid

让人想犯罪 __ 提交于 2019-12-13 17:57:53

问题


I registered with Yandex and got a Translate API Key. However when I try to translate with the following code:

<CFSET Key = "trnsl.1.1.2014091...........................">
<CFSET lang="en-de">
<CFSET text="Hallo World">


<CFHTTP URL="https://translate.yandex.net/api/v1.5/tr.json/translate?Key=#Key#&lang=#lang#&text=#text#"  METHOD = "GET">
</CFHTTP>


<CFOUTPUT>#CFHTTP.FileContent#</CFOUTPUT>

I get a 401 error "API key is invalid". I also tried with Javascript/CFML but got a similar result. I have checked the key, and it is current.

Anyone got something similar working?


回答1:


?Key=#Key#&lang=#lang#&text=#text#

This is going to sound a little crazy, but .. I think the reason is that the url parameter names are case sensitive. Since you are using ?Key= instead of ?key (all lower case) the receiving end thinks you did not supply an API key - at all. Hence the error. (Though "missing or invalid key" would be a little more accurate).

Try using ?key= (all lower case) instead and it should work.



来源:https://stackoverflow.com/questions/25878518/yandex-api-translator-error-401-api-key-is-invalid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!