Sina short URL API interface - turn short long link link

Sina short URL short URL API interface is open to the public Sina generates the interface, you can turn long link short links (generated is http://t.cn/xxxx format) and share a collection of his own api interfaces, using a fast years, has been all kind of stable, feel good can collect it.


Sina Short URL API interface:

http://lnurl.cn/sina/short-api?url_long=http://www.baidu.com


Interface Instructions:

1, online use

The API interface address  "http://www.baidu.com"  parts into their long link, then copy and paste in your browser to open will be able to generate.

2, interface calls

If you feel that online use is too much trouble, you can also be set to directly call API interface program, calling the method can refer to below.

PHP call demo:

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


JAVA call demo:

public static void main(String path[]) throws Exception {
URL u = new URL("http://lnurl.cn/sina/short-api?url_long=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 calls the demo:

import urllib, urllib2, sys
host = 'http://lnurl.cn'
path = '/sina/short-api'
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)


Precautions:

1, when calling API, simply "http://www.baidu.com" replaced the need to shorten the long URL.

2 interface support long links with parameters, but it should be noted that when the & symbol appears on your long link, please use 26% instead of (or use the url encoded), otherwise the parameters may be lost.

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

4, we share the short URL API interface, small series have been used fast one years, is still relatively stable, we feel good about the recall collection, to avoid losing found.


common problem:

1, after a short link generation, and why the original link parameter is missing?

A: Because the original link may contain special characters, you need to shorten long links first and then encoded.

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

A: Sometimes the interface returns the data will be delayed, the delay will not return to lead the build to fail and thus can not return to the interface; or because the original link was closed.

3, Sina short URL generated is valid for how long? There is no limit visits?

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


Guess you like

Origin blog.51cto.com/14635883/2457170