新浪短网址api接口是新浪对外公开的短网址生成接口,可以快速生成t.cn短链接,分享几个最新的新浪短网址api接口,觉得不错可以收藏一下。

 

新浪短网址api接口:

使用说明:

将api接口地址中 "http://www.baidu.com"换成需要缩短的网址,然后直接复制前往浏览器中打开即可。

PHP调用演示:

$url = 'http://www.baidu.com';
$api_url = 'http://kndwz.com/api-tcn.php?link=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://kndwz.com/api-tcn.php?link=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://kndwz.com'
path = 'api-tcn.php?link='
method = 'GET'
querys = 'url=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)

注意事项:

常见问题:

12-17 08:48