在GMOD Wire的表达式2中,Microsoft翻译API存在问题。

我正在使用 Azure 市场上可用的 API,但是当我尝试在 Gmod 13 的 E2 芯片中使用它时,出现以下错误...

The authorization type you provided is not supported.  Only Basic and OAuth are supported

我已经检查了身份验证的方式,但是找不到一个。

这是我的代码...它是从别人使用的 Dictionary.com 翻译器的代码重新制作的,但已经破了。

@name 语言翻译器-由Moglizorz制作-Patched by Scorn(test 6)
@persist Lang:string
#测试1:尝试调整旧的翻译API以检测单词条目。
#测试2:尝试为一词和多词条目添加支持,
#测试3:在测试12失败后,我尝试移至Google Translate。
#测试4:Google没有响应,我找到了Bing翻译器API并尝试使用它。
#测试5:更正上次测试:它是Microsoft翻译API。此外,我一遍又一遍地获得有关授权失败的错误。尝试从https更改为http。
#测试6:由于相同的失败,我已还原测试5,并删除了一些不必要的代码。
runOnChat(1)
runOnHTTP(1)
if(first()){Lang="en"}elseif(duped()){reset()}
if((chatClk(owner()))&(lastSaid():sub(1,6)=="!lang ")){
    hideChat(1)
    print("[Hidden] 将语言设置为: "+lastSaid():sub(6))
    Lang=lastSaid():sub(7,lastSaid():length())
}elseif((lastSaid():sub(1,1)=="~")&(chatClk(owner()))){
    hideChat(1)
    print("[Hidden] 翻译: "+lastSaid():sub(2))
    httpRequest("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate?Text="+httpUrlEncode(lastSaid():sub(2,lastSaid():length()))+"&From=en&to="+Lang )
}
if((httpClk())&(httpRequestUrl():find("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate?Text=")>0)) {
    S=httpData()
    S=S:replace("&","&"):replace(""","\"")
    S=httpUrlDecode(S)
    concmd("say\""+S+"\"")
}
#待添加:双向支持。这样,我正在与之交谈的人的文本将被本地翻译给我。

你可能会注意到一些与 PHP 和 LUA 的相似之处...这就是 E2。

如果您想测试它,您需要 GMOD13,并必须在控制台中使用 wire_expression2_concmd 1。

您还可以在 Expression2归档链接)中找到 E2 语言的任何和所有文档。

点赞
用户1190388
用户1190388

你看到的输出源自以下声明:

httpRequest(“https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate?Text =”+httpUrlEncode(lastSaid():sub(2,lastSaid():length()))+“&From=en&to =”+Lang)

根据Microsoft Translator模式

该服务支持固定查询。某些查询可能包括必需的输入参数。

我强调

现在,在帮助文档中也覆盖了创建固定查询的方法这个主题。正如您在文档的第4步中看到的那样,您会看到他们有:

private const string USER_ID = "yourLiveId";
private const string SECURE_ACCOUNT_ID = "yourMarketplaceAccountKey";  // not your Live password
private const string ROOT_SERVICE_URL = "https://api.datamarket.azure.com/Data.ashx/Alteryx/CensusDemographicData";

同一代码块中稍后

public CensusDemographicData()
{
    serviceUri = new Uri(ROOT_SERVICE_URL);
    context = new CensusDemographicDataContainer(serviceUri);
    context.IgnoreMissingProperties = true;
    context.Credentials = new NetworkCredential(USER_ID,
                                                SECURE_ACCOUNT_ID);

您的查询中缺少Credentials参数; 这根本不是固定的。

2013-10-14 11:42:49