Tencent (url.cn) short URL link generated api interfaces

A brief description

Short URL url Tencent Tencent api interface is a long URL into a short official publicly URL API, lengthy short link address can be shortened URL generated url.cn/xxx format.

 

API request address

1、http://lnurl.cn/weixin/short?link=http://www.baidu.com

2、http://kndwz.com/api-urlcn.php?url=http://www.baidu.com

 

Request method

  • POST

 

Request parameter

parameter required Types of Explanation
key Yes string Register Login acquisition

Interface key is authorized on behalf of a user's unique identity when the call interface. url link url and behind the link is long links need to be converted, if your url with parameters or in special symbols needs to be done URLENCODE treatment, this may result in the loss parameters.

 

Application of the key steps

1, enter  http://lnurl.cn/api/urlcn  , select the API interface.

2, create a unique user id go interface management console.

3, the interface obtaining authorization key, key that uniquely identifies the interface requests.

4. Copy the API interface address, you can call generate short links.

 

Interface instructions

1, online use

Two interfaces mentioned above is free and open interface, without the authorization key to the normal call. For online use, just put in the back of the interface link 1 and link interfaces url back links into 2 long they need to convert URL, then copy the whole string browser to open links go to generate the corresponding short URL.

2, the request interface

High demand friend, do not recommend generation online, it is more troublesome, time-consuming, would have a direct access interface, interface generation program request.

 

Request Interface Example

1, PHP sample request:

1 $url = 'http://www.baidu.com';
2 $api_url = 'http://lnurl.cn/weixin/short?link=http://www.baidu.com;
3 $short_url = file_get_contents($api_url);
4 echo $short_url;

 

2, Java sample request:

 1 public static void main(String path[]) throws Exception {
 2 URL u = new URL("http://lnurl.cn/weixin/short?link=http://www.baidu.com");
 3 InputStream in = u.openStream();
 4 ByteArrayOutputStream out = new ByteArrayOutputStream();
 5 try {
 6 byte buf[] = new byte[1024];
 7 int read = 0;
 8 while ((read = in .read(buf)) > 0) {
 9 out.write(buf, 0, read);
10 }
11 } finally {
12 if ( in != null) {
13 in .close();
14 }
15 }
16 byte b[] = out.toByteArray();
17 System.out.println(new String(b, "utf-8"));
18 }

 

3, Python sample request:

 1 import urllib, urllib2, sys
 2 host = 'http://lnurl.cn'
 3 path = '/weixin/short'
 4 method = 'GET'
 5 querys = 'link=http%3A%2F%2Fwww.baidu.com'
 6 bodys = {}
 7 url = host + path + '?' + querys
 8 request = urllib2.Request(url)
 9 response = urllib2.urlopen(request)
10 content = response.read()
11 if (content):
12 print(content)

 

Precautions:

1, the API request, or later want to link corresponding to url "http://www.baidu.com" URL with the need to shorten the length of their URLs.

2, the interface supports links have parameters, but it should be noted that when the & symbol appears in the link, use 26% instead of (or use the url encoded), otherwise the parameters may be lost.

3, replace the link, must be based on http (s): // at the beginning, this may result in failure to generate or generate short URL short URL to access the original site can not jump.

 

common problem:

1, long after link translation parameters why the end is lost?

A: Because long link contains special characters, you need to url encoding before use interface generation.

2, the interface does not return results, what is the situation?

A: Sometimes the interface returns the data will be delayed, which generates a timeout failure does not return, it will not return result; or because the original link was closed.

3, valid for generating the short URL is how long? There is no limit visits?

A: url short URL Generator is permanent, there is no limit clicks, you can rest assured that use.

Guess you like

Origin www.cnblogs.com/zandnsn/p/12085263.html