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

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

问题描述

我需要为我的应用提供翻译API服务,并选择了 Google翻译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可以检测到可疑流量(可悲的是,它发生在我身上),因此您会收到一条错误消息.我不确定您可以使用多长时间,直到他们能够检测到您的活动,所以我的建议是使用免费服务"对您的应用进行广泛的测试,如果您遇到麻烦,也许应该购买该服务或寻求其他服务API. 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天全站免登陆