Tencent url short URL, url.cn short link to generate the interface, URL shortening api

Short URL url Tencent Tencent is the use of the official URL shortener API to generate transformed from, the interface can be used to shorten a long URL to generate short links within 15 characters, the format is http://url.cn/xxxx. As t.cn short URLs Xinlang interfaces open to the public, are a relatively short URLs generated stable interfaces, the interfaces generated by the short URLs are permanently effective.

Practical scene

Tencent url short URL more is to promote the application within the micro-channel can also be used in SMS marketing, email promotion, QQ marketing, self media promotion, channel promotion, as to why most of the promotion in the micro letter, the reason is short URL that can reduce marketing costs, the cost of user memory, increase the advantages of user click-through rates, but the most valued thing we can avoid the use of keywords in the micro-channel to prevent the original link was blocked.

interface address

Formats: http://lnurl.cn/url-api.json?url=http://www.baidu.com

Format two: http://www.ldurl.cn/short-urlcn?link=http://www.baidu.com

Three formats: http://qturl.cn/urldwz/api.html?url_long=http://www.baidu.com

Schemes for Fourth: http://www.66kuaitu.cn/urlcn.php?url=http://www.baidu.com

Five formats: http://kndwz.com/url-api.php?link=http://www.baidu.com

Development Documentation

1, request method

  • GET 

2, sample request

http://lnurl.cn/url-api.json?url=http://www.baidu.com

3, return form

  • Direct return "https://url.cn/xxxx"

4. Use

① online use

Simply "http://www.baidu.com" need to shorten long URLs into (with the http (s): //), then copy the whole string browser to open links go to generate.

c5cde6f8d35a724b.jpg

② request interface

Generating the server request interface is provided, each time a request to return a result, the following sample code is requested.

5, sample request

① PHP

$url = 'http://www.baidu.com';
$api_url = 'http://lnurl.cn/url-api.json?url=http://www.baidu.com;
$short_url = file_get_contents($api_url);
echo $short_url;

② Java

public static void main(String path[]) throws Exception {
URL u = new URL("http://lnurl.cn/url-api.json?url=http://www.baidu.com");
InputStream in = u.openStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte buf[] = new byte[1024];
int read = 0;
while ((read = in .read(buf)) > 0) {
out.write(buf, 0, read);
}
} finally {
if ( in != null) {
in .close();
}
}
byte b[] = out.toByteArray();
System.out.println(new String(b, "utf-8"));
}

③ Python

import urllib, urllib2, sys
host = 'http://lnurl.cn'
path = '/url-api.json'
method = 'GET'
querys = 'url_long=http%3A%2F%2Fwww.baidu.com'
bodys = {}
url = host + path + '?' + querys
request = urllib2.Request(url)
response = urllib2.urlopen(request)
content = response.read()
if (content):
print(content)

 

Tips:

1, when the request interface, if the short URL to generate micro-letters, found the tail of the original URL parameter is missing how to do? Urlencode do need to deal with the original link, and then go to generate.

2, the long URL request interface must be to http (s): // at the beginning, as this may cause the build to fail.

3, interface request frequency recommended not too fast, normal 1 / s, completely sufficient.

common problem:

1, after long URLs into why the argument is lost?

A: Because not do urlencode process, resulting in some special characters not recognized. The encoder then needs to request interface url.

2, request interface Why did not return a result?

A: Sometimes there is a delay data interface to return, it will lead to time-out did not return. Or because the original link was closed.

3, url generate a short URL is valid for how long? There is no limit visits?

A: Share short URL generated interface is valid, the official version of the interface to generate short URLs are permanently valid.

4, there is no short URL access restrictions?

A: This interface is based on the official website interfaces developed, no visits limited, and ease of use.


Guess you like

Origin blog.51cto.com/14758627/2479672