2017-01-31 5 views
0

私はgoogleにapiプレミアムエディションとjsonを翻訳するのは初めてです。私は、サービスアカウントと主要な資格情報をjsonファイルに保存しています。私は 'nmt'モデルを使いたいです。以下は私のPythonコードです。私はアクセストークンを取得することはできますが、それでも正しく動作させることはできません。私が間違った部分を教えてください。私はあなたの助けに感謝します。jsonによってプレミアムAPIをGoogle翻訳する

from oauth2client.client import GoogleCredentials 
from googleapiclient.discovery import build 

base_url = ['https://www.googleapis.com/language/translate/v2'] 

# load json credential keys 
my_credentials = GoogleCredentials.from_stream('./data/TranslateAPI-cbe083d405fe.json') 

# get access token 
access_token = my_credentials.get_access_token(base_url) 

# build service 
service = build('translate', 'v2', credentials=access_token, model='nmt') 

text = u'So let us begin anew--remembering on both sides that civility is not a sign of weakness, and sincerity is always subject to proof. Let us nevernegotiate out of fear. But let us never fear to negotiate.' 
test = service.translations().list(q=text, target='es') 
results = test.execute() 

私は、次のエラーを得た:

Traceback (most recent call last): 
File "C:\Users\ying\workspace\GoogleTranslateAPI_v3\test1.py", line 32, in <module> 
test = service.translations().list(q=text, target='es') 
File "C:\Anaconda\lib\site-packages\googleapiclient\discovery.py", line 778, in method 
headers, params, query, body = model.request(headers, 
AttributeError: 'str' object has no attribute 'request' 

答えて

0

あなたが使用しているクライアントは、 "NMT" をサポートしていませんGoogle Cloud Translate Client を使用する必要があります。この場合のエラーは、「モデル化」パラメータに間違ったタイプの値を入力したことです。正しい値はgoogleapiclient.Model

です。
関連する問題