2016-04-17 136 views
0

我正在通過curl測試Google翻譯API,並且它一直詢問參數q,而它已經存在於URL中(q = Hello%20World)。爲什麼Google翻譯API會返回此錯誤?通過curl測試谷歌翻譯API

捲曲https://www.googleapis.com/language/translate/v2?key= &源= EN &目標= DE & Q =你好%20World

[1] 16848 
[2] 16849 
[3] 16850 
[2]- Done     source=en 
[3]+ Done     target=de 
foo:~ foo$ { 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "required", 
    "message": "Required parameter: q", 
    "locationType": "parameter", 
    "location": "q" 
    }, 
    { 
    "domain": "global", 
    "reason": "required", 
    "message": "Required parameter: target", 
    "locationType": "parameter", 
    "location": "target" 
    } 
    ], 
    "code": 400, 
    "message": "Required parameter: q" 
} 
} 

幫助?

回答

2

你必須圍繞你的整個URL在雙引號,如:

curl "https://www.googleapis.com/language/translate/v2?key=&source=en&target=de&q=Hello%20World"

否則,你的shell會解釋實際執行curl之前那些&字符;這就是爲什麼你看到所有這些行開頭:

[1] 16848 
[2] 16849 
[3] 16850 
[2]- Done     source=en 
[3]+ Done     target=de