This article mainly introduces the php Youdao translation api call method. The example analyzes the call methods and related skills of Youdao translation API, which is of great practical value, for more information, see the example in this article. We use the file_get_contents function to directly read and process the data returned by the api. The specific analysis is as follows:
Before calling the API, we need to apply for a key to Translate API data. The address is as follows:
The code is as follows:
Http://fanyi.youdao.com/openapi? Path = data-mode
Method description, data interface:
The code is as follows:
Http://fanyi.youdao.com/openapi.do? Keyfrom = & Key = & Amp; type = data & doctype = & Version = 1.1 & q = text to be translated
Parameter description:
Type-type of the returned result, fixed to data
Doctype-data format of the returned results, xml, json, or jsonp
Version-version. The latest version is 1.1.
Q-the text to be translated cannot exceed 200 characters and must be UTF-8 encoded
ErrorCode:
0-normal
20-the text to be translated is too long
30-no valid translation is available
40-unsupported language types
50-invalid key
The PHP instance code is as follows:
The code is as follows:
$ Url = "http://fanyi.youdao.com/openapi.do? Keyfrom = xujiangtao & key = 1490852988 & type = data & doctype = json & version = 1.1 & q = ". $ content;
$ List = file_get_contents ($ url );
$ Js_de = json_decode ($ list, true );
Note: When using the API key, the request frequency is limited to 1000 times per hour. if the limit is exceeded, the request will be banned.
If your application does require more than 1000 requests per hour, please contact the translate-service@corp.youdao.com and provide your application details, name, function, website address, API method, API key, expected access frequency, commercial behavior, screenshot, and so on, as well as the server IP address used when the application accesses the Youdao translation API, access restrictions can be relaxed after the review is passed.
I hope this article will help you with PHP programming.