Yandex API转换器错误-401 API密钥无效 [英] Yandex API Translator error - 401 API key is invalid

查看:259
本文介绍了Yandex API转换器错误-401 API密钥无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Yandex上注册并获得了翻译API密钥.但是,当我尝试使用以下代码进行翻译时:

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>

我收到401错误"API密钥无效".我也尝试使用Javascript/CFML,但得到了类似的结果.我已经检查了钥匙,它是最新的.

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?

推荐答案

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

这听起来有点疯狂,但是..我认为原因是url参数名称区分大小写.由于您使用的是?Key=而不是?key(均小写),因此接收端认为您根本没有提供API密钥.因此,错误. (尽管丢失或无效密钥"会更准确一些.)

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

尝试改用?key=(所有小写字母),它应该可以工作.

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

这篇关于Yandex API转换器错误-401 API密钥无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆