PHP Youdao Translation API call method instance _php tips

Source: Internet
Author: User

The example of this article tells the PHP Youdao translation API call method, here we use the File_get_contents function directly read by the API returned data processing, share for everyone reference. The specific analysis is as follows:

Before calling we need to apply for a Youdao translation API data interface key, address such as:

Copy Code code as follows:
Http://fanyi.youdao.com/openapi?path=data-mode

Method description, Data interface:

Copy Code code as follows:
http://fanyi.youdao.com/openapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=< Doctype>&version=1.1&q= the text to be translated

Parameter description:

Type-Returns the types of the result, fixed to data

DOCTYPE-Returns the data format of the result, XML or JSON or JSONP

Version-edition, current latest version is 1.1

Q-The text to be translated cannot exceed 200 characters and requires the use of UTF-8 encoding

ErrorCode:

0-Normal

20-The text to be translated is too long

30-Unable to perform a valid translation

40-Unsupported language type

50-Invalid Key

The PHP instance code is as follows:

Copy Code code 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, and the limit is banned.

If your application does require more than 1000 requests per hour, please contact translate-service@corp.youdao.com and provide details of your application, name, function, website address, how to use the API, API key, estimated frequency of access, Whether business behavior, screenshots, etc., and the application Access Youdao translation API used by the server IP, after the audit can be relaxed access restrictions.

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.