Google Translate API(付费)与 Google Translate API(免费)? [英] Google Translate API (paid) vs Google Translate API (free)?

查看:104
本文介绍了Google Translate API(付费)与 Google Translate API(免费)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用需要 Translate API 服务,并选择了 Google Translate API,它将花钱并需要针对 Google API 进行身份验证.但是在搜索过程中,我发现了这个链接,它看起来可以免费使用,并且可以免费执行我需要的操作:

I need Translate API service for my app and have chosen Google Translate API, which will cost money and require authentication against the Google API. But during the search I've found this link which looks freely available and do what I need without cost:

https://translate.google.so/translate_a/t?client=any_client_id_works&sl=auto&tl=ru&q=wrapper&tbb=1&ie=UTF-8&oe=UTF-8

尝试发出 GET 请求,您会自己看到.

Try to issue a GET request and you'll see it by yourself.

那么,我的问题是上述这些服务之间有什么区别,我是否有权使用第二个服务?

So, my question is what is the difference between these above services and am I authorized to use the second one?

推荐答案

当然它是免费的,你可以实施它(我在下面包含了一个例子).但是,不要使用它,因为一段时间后 Google 可以检测到可疑流量——这发生在我身上,很遗憾——所以你会收到一条错误消息.我不确定在他们检测到您的活动之前您可以使用它多长时间,因此我对您的建议是使用免费服务"广泛测试您的应用程序,如果您发现一些问题,也许您应该购买该服务或寻找其他服务应用程序接口.https://api.mymemory.translated.net 是一种免费但有限的替代方案.

Of course it is free and you can implement it (I included an example below). However, DO NOT USE IT because after a while Google can detect suspicious traffic –it happened to me, sadly- so you will receive an error message. I'm not sure how long can you use it until they can detect your activity so my advice for you is to test extensively your app with the "free service" and if you see some troubles perhaps you should buy the service or look for another API. https://api.mymemory.translated.net is a free but limited alternative.

在 iOS Swift 4 中,您可以使用以下函数实现免费服务:

In iOS Swift 4 you can implement the free service by using the following function:

func translate(str: String, lang1: String, lang2: String) {

    let escapedStr = str.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
    let lastPart = lang1 + "&tl=" + lang2 + "&dt=t&dt=t&q=" + escapedStr!
    let urlStr: String = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + lastPart
    let url = URL(string: urlStr)

    let task = URLSession.shared.downloadTask(with: url!) { localURL, urlResponse, error in
        if let localURL = localURL {
            if let string = try? String(contentsOf: localURL) {
                let index = string.firstIndex(of: """)
                let index2 = string.index(after: index!)
                let subst = string.substring(from: index2)
                let indexf = subst.firstIndex(of: """)
                let result = subst.substring(to: indexf!)
                DispatchQueue.main.async {
                    if flag1country != flag2country {
                        self.texto.text = result
                    }
                }
            }
        }
    }
    task.resume()
}

(也许这不是最好的实现,但它有效).

(Perhaps this is not the best implementation, but it works).

这篇关于Google Translate API(付费)与 Google Translate API(免费)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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