短链接接口


下文为青桃短链接api使用说明,请使用前仔细阅读!!

接口请求地址


1.新浪短链接API

http://qturl.cn/tcn/api?key=xxxxxxxx&url=http://www.baidu.com

2.腾讯短链接API

http://qturl.cn/urlcn/api?key=xxxxxxxx&url=http://www.baidu.com

使用说明:
1、注册登录,获取接口授权key
2、请求接口,请求时将 “http://www.baidu.com” 换成需要缩短的长链接即可

PHP调用示例


$url = 'http://www.baidu.com';

$api_url = 'http://qturl.cn/tcn/api?key=xxxxxxxx&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://qturl.cn/tcn/api?key=xxxxxxxx&url=http://www.baidu.com");

InputStream in = u.openStream();

ByteArrayOutputStream out = new ByteArrayOutputStream();

try {

byte buf[] = new byte[1024];

int read = 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://qturl.cn'

path = '/tcn/api?key=xxxxxxxx'

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)