Home > Article > Backend Development > PHP Youdao translation api calling method example, PHP Youdao api example_PHP tutorial
The example in this article describes the calling method of PHP Youdao Translation API. Here we use the file_get_contents function to directly read the data returned by the API for processing and share it with everyone for your reference. The specific analysis is as follows:
Before calling, we need to apply for a key for the Youdao Translation API data interface, the address is such as:
Method description, data interface:
Parameter description:
type - the type of the returned result, fixed to data
doctype - the data format of the returned result, xml or json or jsonp
version - version, the latest version is 1.1
q - The text to be translated cannot exceed 200 characters and needs to be encoded in UTF-8
errorCode:
0 - Normal
20 - The text to be translated is too long
30 - No valid translation possible
40 - Unsupported language type
50 - Invalid key
PHP example code is as follows:
If your application does require more than 1,000 requests per hour, please contact translate-service@corp.youdao.com and provide the details of your application, name, function, website address, how to use the API, API key, expected access frequency, whether it is a commercial activity, screenshots, etc., as well as the server IP used by the application to access Youdao Translation API. Access restrictions can be relaxed after approval.
I hope this article will be helpful to everyone’s PHP programming design.