新浪短网址已经广泛应用于各大平台营销之中. 如: 微信, 短信, 微博已经各论坛广告软文之中. 因为其超短的 t.cn 的样式, 更容易让人接收和保证的文案的美观性. 但是自新浪停止了对外开放的 API key 之后, 市面上还有哪些可以继续生成新浪短网址的 API 接口呢? 别担心, 今天给大家分享一款我自己一直在使用的新浪短网址 API 接口.
新浪微博短网址 API 接口:
接口 1:http://qingmeidwz.cn/shorten.php?url_long=http://www.baidu.com http://qingmeidwz.cn/
接口 2:http://muzidwz.cn/sina_short.php?data=http://www.baidu.com http://muzidwz.cn/
地址 1: http://qingmeidwz.cn/
地址 2: http://muzidwz.cn/
使用说明:
将 API 接口地址中 "http://www.baidu.com" 换成需要缩短的网址, 然后直接复制前往浏览器中打开即可.
PHP 调用演示:
- $url = 'http://www.baidu.com';
- $api_url = 'http://qingmeidwz.cn/shorten.php?url_long=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://qingmeidwz.cn/shorten.php?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 调用演示:
- import urllib, urllib2, sys
- host = 'http://qingmeidwz.cn/'
- path = 'shorten.php?url_long='
- method = 'GET'
- querys = 'url=http://www.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://www.baidu.com" 换成需要缩短的长网址即可.
2 接口支持 url 参数, 当 url 中出现 & 符号时, 请用 & 代替, 否则参数可能会丢失.
3 填写 url 时, 必须要以 http(s):// 开头, 否则可能会导致生出的短网址无法访问原网站.
4 上文的 t.cn 短网址 API 接口, 经测试非常稳定, 觉得好记得收藏一下, 以免丢失.
常见问题:
1 长链接转换, 为什么结尾的参数丢失了?
答: 因为 url 中含有特殊字符, 需要使用 UTF8 编码格式, 将 url 编码
2 接口没有返回结果, 是什么情况?
答: 有些时候接口返回数据会有延迟, 延时未返回则会提示生成失败; 或者是因为原链接被封了.
3 生成的 t.cn 短网址有效期是多久? 有没有访问次数限制?
答: 生成的 t.cn 短网址永久有效的, 而且没有点击次数限制, 可以任意使用
来源: http://www.bubuko.com/infodetail-3355973.html