Sina Weibo provides a long time before the long links into short links API, you can put long links into short links t.cn/xxx this format. But in September of this year, Sina due to the adjustment of policy, the previous interface to shut down!
Many small partners have encountered confusion Sina short link to it, some of my friends have seen piecemeal approach online Sina short link, and did not completely understand how Sina short links are solved, Xiao Bian today to prepare simple solutions way, we only need to follow the tutorial can operate, so today I gave you recommend a few short links Sina API interface we're using now, and I hope you can help to you! ! !
Sina short URL API interface
Interface address: HTTP:? //Www.wx-dwz.cn/tcnurl url = https://www.baidu.com
Interface address: HTTP: //mhdwz.cn/mhsina url =? Http://www.baidu.com
Interface address: HTTP: //maiyurl.cn/weibourl url =? Http://www.baidu.com
Interface Address: http://www.qqdwz.cn/tcn/api url =? Http://www.baidu.com
Short URL Tencent API interface
Interface Address: http://www.qqdwz.cn/urlcn/api url_long =? Http://www.baidu.com
Interface Address: http://maiyurl.cn/tengxurl?url_long=http://www.baidu.com
Interface Address: http://www.sina-url.cn/urlcn/api?url_long=http://www.baidu.com
Short URL API instructions
The above short URL api interface "http://www.baidu.com "section with the long link you need to generate a short URL corresponding Sina!
Sina short URL interface documentation
PHP calling code:
$url = 'http://www.baidu.com'; $api_url = ''.urlencode($url); $short_url = file_get_contents($api_url); echo $short_url;
JAVA calling code:
public static void main(String path[]) throws Exception { URL u = new URL("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 = '' path = '' method = 'GET' querys = '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)