新浪短链接api申请

接口1:

http://sina-t.cn/api?link=http://baidu.com

接口2:

http://tttool.cn/sina_api?url=http://baidu.com

接口3:

http://knurl.cn/tcnapi?url_long=http://baidu.com

接口4:

http://migourl.cn/sina_shorturl.html?text=http://baidu.com

使用方法:

将最后的"http://baidu.com"换成要缩短的长链接即可,可以程序调用,也可以直接访问得到结果
这四个接口返回格式相对而言比较简单,直接返回结果

调用demo

PHP调用代码:

$url = 'http://www.baidu.com';
$api_url = 'http://sina-t.cn/api?link='.urlencode($url);
$short_url = file_get_contents($api_url);
echo $short_url;

JAVA调用代码:

public static void main(String path[]) throws Exception {
URL u = new URL("http://sina-t.cn/api?link=http%3A%2F%2Fwww.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://sina-t.cn'
path = 'api'
method = 'GET'
querys = 'link=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)

注意事项

1、调用api接口时,只需将 “http://baidu.com”换成需要缩短的长网址即可。
2、接口支持url参数,当链接中出现 & 符号时,请用 %26 代替(或者使用url编码),否则参数可能会丢失。
3、填写链接时,必须要以http(s)://开头,否则可能会导致生出的短网址无法访问原网站。