In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "php, java, Python how to call Sina short link api interface", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "php, java, Python how to call Sina short link api interface"!
1. APIKEY Get:
http://url-t.cn/api
2. calling code
PHP call code
$url = 'http://www.baidu.com'; $api\_url = 'http://url-t.cn/tcn/api? key=APIKEY/tcn\_url? url='.urlencode($url); $short\_url = file\_get\_contents($api\_url); echo $short\_url;
Java call code
public static void main(String path\[\]) throws Exception { URL u = new URL("http://url-t.cn/tcn/api? key=APIKEY&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 call code
import urllib, urllib2, sys host = 'http://url-t.cn' path = '/tcn/api' method = 'GET' querys = 'key=APIKEY&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)3. Docking prompt:
a. Long links need url encoding, especially those with parameters after the link, which must be encoded first.
b. Long links need to have a protocol header, http://or https://
c.APIKEY is a unique identification code, which needs to be replaced with your own KEY before docking.
d. It is recommended to add exception handling to the code. Because of network patency, timeout exceptions may occur.
At this point, I believe that everyone has a deeper understanding of "php, java, Python how to call Sina short link api interface", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.