這篇文章主要介紹“php和python怎么調(diào)用短網(wǎng)址生成api接口”,在日常操作中,相信很多人在php和python怎么調(diào)用短網(wǎng)址生成api接口問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”php和python怎么調(diào)用短網(wǎng)址生成api接口”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
調(diào)用方法(以新浪t.cn短鏈接api接口為例):
PHP調(diào)用演示:
$url = 'http://www.baidu.com'; $api_url = 'http://qingmeidwz.cn/shorten.json?url_long=http://www.baidu.com'; $short_url = file_get_contents($api_url); echo $short_url;
JAVA調(diào)用演示:
public static void main(String path[]) throws Exception { URL u = new URL("http://qingmeidwz.cn/shorten.json?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調(diào)用演示:
import urllib, urllib2, sys host = '/tupian/20230522/& path = 'shorten.json?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)
注意事項(xiàng):
① 調(diào)用api接口時(shí),只需將 “http://www.baidu.com”換成需要縮短的長網(wǎng)址即可。
② 接口支持url參數(shù),當(dāng)url中出現(xiàn) & 符號(hào)時(shí),請(qǐng)用 %26 代替,否則參數(shù)可能會(huì)丟失。
③ 填寫url時(shí),必須要以http(s)://開頭,否則可能會(huì)導(dǎo)致生出的短網(wǎng)址無法訪問原網(wǎng)站。
④ 上文的微信url.cn,新浪t.cn短網(wǎng)址api接口,經(jīng)測試非常穩(wěn)定,覺得好記得收藏一下,以免丟失。
常見問題:
① 長鏈接轉(zhuǎn)換,為什么結(jié)尾的參數(shù)丟失了?
答:因?yàn)閡rl中含有特殊字符,需要使用UTF8編碼格式,將url編碼
② 接口沒有返回結(jié)果,是什么情況?
答:有些時(shí)候接口返回?cái)?shù)據(jù)會(huì)有延遲,延時(shí)未返回則會(huì)提示生成失??;或者是因?yàn)樵溄颖环饬恕?/p>
③ 生成的短網(wǎng)址有效期是多久?有沒有訪問次數(shù)限制?
答:生成的短網(wǎng)址都是永久有效的,而且沒有點(diǎn)擊次數(shù)限制,可以任意使用
到此,關(guān)于“php和python怎么調(diào)用短網(wǎng)址生成api接口”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
分享名稱:php和python怎么調(diào)用短網(wǎng)址生成api接口-創(chuàng)新互聯(lián)
網(wǎng)頁網(wǎng)址:http://jinyejixie.com/article20/dpdgjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、App開發(fā)、網(wǎng)站營銷、做網(wǎng)站、微信公眾號(hào)、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容