Javascript Google音译API未通过https提供 [英] Javascript Google transliterate API not served over https

查看:88
本文介绍了Javascript Google音译API未通过https提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 JavaScript google transliterate API不通过https提供服务。我得到混合内容错误。它在http网站上工作,但没有使用https。我试图通过以下所有方式调用API。



错误

混合内容:https://extranuclear-freque.000webhostapp.com/lang.html页面是通过HTTPS加载的,但请求了一个不安全的脚本http://www.google.com /inputtools/request?text=gy&ime=transliteration_en_bn&num=5&cp=0&cs=0&ie=utf-8&oe=utf-8&app=jsapi&uv&cb=callbacks._2j46jfkrs'。此请求已被阻止;内容必须通过HTTPS提供。





我尝试过:



< html> 
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< script type =text / javascriptsrc =https://google.com/jsapi>
//加载Google Transliterate API
google.load(elements,1,{
packages:transliteration
});

函数onLoad(){
var options = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.HINDI],
shortcutKey:'ctrl + g',
transliterationEnabled:true
};

//使用所需的
//选项在TransliterationControl上创建一个实例。
var control =
new google.elements.transliteration.TransliterationControl(options);

//在ID为
//'transliterateTextarea'的文本框中启用音译。
control.makeTransliteratable(['transliterateTextarea']);
}
google.setOnLoadCallback(onLoad);
< / script>
< / head>
< body>
键入印地语(按Ctrl + g在英语和印地语之间切换)< br>
< textarea id =transliterateTextareastyle =width:600px; height:200px>< / textarea>
< / body>
< / html>

解决方案

七年前该API已被弃用!

Google Transliterate API已被正式弃用为2011年5月26日。



弃用政策 [ ^ ]他们表示他们将尽最大努力使其保持运行长达三年之久那个日期。之后,他们可以随时撤销API,恕不另行通知。



可能能够使用upgrade-insecure-requests [ ^ ] CSP强制脚本加载HTTPS。但是不能保证它会起作用,并且谷歌很有可能在没有通知的情况下终止API而破坏你的网站。



你需要找到一个替代API以满足您的要求。


Google在翻译中有硬编码.js



对于这个问题,您可以下载以下内容提交并上传到您自己的服务器并将

  http://google.com 更改为 https://google.com   


(https://www.google.com/uds/api/elements/1.0/7ded0ef8ee68924d96a6f6b19df266a8/ transliteration.I.js)


JavaScript google transliterate API is not serving over https. Im getting below mixed content error . Its working over http website, but not working with https. I have tried to invoke the API in all the below ways.


Error

Mixed Content: The page at 'https://extranuclear-freque.000webhostapp.com/lang.html' was loaded over HTTPS, but requested an insecure script 'http://www.google.com/inputtools/request?text=gy&ime=transliteration_en_bn&num=5&cp=0&cs=0&ie=utf-8&oe=utf-8&app=jsapi&uv&cb=callbacks._2j46jfkrs'. This request has been blocked; the content must be served over HTTPS.



What I have tried:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="https://google.com/jsapi">    
      // Load the Google Transliterate API
      google.load("elements", "1", {
            packages: "transliteration"
          });

      function onLoad() {
        var options = {
            sourceLanguage:
                google.elements.transliteration.LanguageCode.ENGLISH,
            destinationLanguage:
                [google.elements.transliteration.LanguageCode.HINDI],
            shortcutKey: 'ctrl+g',
            transliterationEnabled: true
        };

        // Create an instance on TransliterationControl with the required
        // options.
        var control =
            new google.elements.transliteration.TransliterationControl(options);

        // Enable transliteration in the textbox with id
        // 'transliterateTextarea'.
        control.makeTransliteratable(['transliterateTextarea']);
      }
      google.setOnLoadCallback(onLoad);
    </script>
  </head>
  <body>
    Type in Hindi (Press Ctrl+g to toggle between English and Hindi)<br>
    <textarea id="transliterateTextarea" style="width:600px;height:200px"></textarea>
  </body>
</html> 

解决方案

That API was deprecated seven years ago!

The Google Transliterate API has been officially deprecated as of May 26, 2011.


The deprecation policy[^] says they'll do their best to keep it running for up to three years from that date. After that, they can withdraw the API at any time, without notice.

You might be able to use the upgrade-insecure-requests[^] CSP to force the script to load over HTTPS. But there's no guarantee that it will work, and a very real possibility that Google will terminate the API without notice and break your site.

You'll need to find an alternative API to meet your requirements.


Google having hardcode in translation.js

For this issue, you can download the below file and upload to your own server and change the

http://google.com to https://google.com

that will solve your problem

(https://www.google.com/uds/api/elements/1.0/7ded0ef8ee68924d96a6f6b19df266a8/transliteration.I.js)


这篇关于Javascript Google音译API未通过https提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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