Yandex API Translator error - 401 API key is inval

2019-07-25 11:46发布

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条回答
祖国的老花朵
2楼-- · 2019-07-25 12:10

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

查看更多
登录 后发表回答