您现在的位置是:首页 > 文章详情

新浪短链接api申请

日期:2019-12-10点击:598

接口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)://开头,否则可能会导致生出的短网址无法访问原网站。

原文链接:https://yq.aliyun.com/articles/738965
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章