Example of api call method

Source: Internet
Author: User
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.

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.