【问题标题】:How to run Google Translate v3 using KEYAPI?如何使用 KEYAPI 运行谷歌翻译 v3?
【发布时间】:2020-12-27 01:59:02
【问题描述】:

所以这是我尝试的:

# running Translate API
from googleapiclient.discovery import build
service = build('translate', 'v3', developerKey=APIKEY)

# use the service
inputs = ['is it really this easy?', 'amazing technology', 'wow']
print(service)
outputs = service.translate_text().list(source='en', target='fr', q=inputs).execute()
# print outputs
for input, output in zip(inputs, outputs['translations']):
  print(u"{0} -> {1}".format(input, output['translatedText']))

这是我得到的:

<googleapiclient.discovery.Resource object at 0x7f35c6755278>
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-cae7afc56ddd> in <module>()
      6 inputs = ['is it really this easy?', 'amazing technology', 'wow']
      7 print(service)
----> 8 outputs = service.translate_text().list(source='en', target='fr', q=inputs).execute()
      9 # print outputs
     10 for input, output in zip(inputs, outputs['translations']):

AttributeError: 'Resource' object has no attribute 'translate_text'

在翻译 v3 sample 中,我找不到如何使用 APIKEY 代替 project_id...类似的 API 适用于 v2(例如 here)。

那么如何使用 KEYAPI 运行 Google Translate v3?

【问题讨论】:

  • 使用 project_id 而不是 api_key 有什么问题?

标签: python-3.x api google-cloud-platform translation


【解决方案1】:

V3 不支持 API KEY,详情请见this page

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 2011-06-06
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    相关资源
    最近更新 更多