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
Sina Weibo provides long links into short links T.cn API interface, we can put before the long link into t.cn/xxx short link in this format. Facilitate our promotion. Now I gave you a new way to apply for short links API interface Sina T.cn!
Key application API interface
①, enter http://www.sinadwz.cn/ , select the top right corner of the menu Registration -> fill out the account password.
②, click Sign up now, registration is successful, move the mouse to the top right of your account, click on the individual centers!
③, into the personal center, we can see their Key up! (Please keep your Key)
API Interface Description
Please keep the distribution system of Key, Key when the call interface represents a unique identity applications. Test, then directly replace url = link back to their own need to convert long links, you can use!
Precautions:
① When calling api interfaces, simply fill out the required length of the URL in the URL = compression generated behind.
② interface supports url parameters, when the & symbol appears in the url, use 26% instead of (or use the url encoding format), or parameters may be lost.
When ③ fill url, must be based on http (s): // at the beginning, it may cause a short URL to give birth can not access the original site.
Several url.cn short URL api interfaces ④ mentioned above, the tests are relatively stable, it felt good to remember collection, to avoid loss.
common problem:
① long link translation parameters why the end is lost?
A: Because the url contains special characters, you need to use UTF8 encoding format, the url coding!
② interface does not return a result, what is the situation?
A: Sometimes the interface returns the data will be delayed, the delay did not return will be prompted to generate a failure; or because the original link was closed.
Short URL generated is valid ③ how long? There is no limit visits?
A: The short URL is generated url permanent and effective, and there is no limit clicks, you can use any!
Calling code
PHP call demo:
$url = 'http://www.baidu.com'; $ Api_url = 'http://www.sinadwz.cn/sina.php?url_long=http://www.baidu.com; $short_url = file_get_contents($api_url); echo $short_url;
JAVA call demo:
public static void main(String path[]) throws Exception { URL u = new URL("http://www.sinadwz.cn/sina.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 calls the demo:
import urllib, urllib2, sys host = 'http://www.sinadwz.cn/' path = 'sina.php?url_long=' 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)