轉載,原文鏈接:http://www.cnblogs.com/e241138/archive/2012/07/21/2602405.html
新浪舊版開發文檔地址:http://open.weibo.com/wiki/Short_url/shorten
新浪短網址接口的穩定性和跳轉速度還是很給力的,現給出其API說明。
該接口支持兩種返回格式:xml和json
對應的URL請求地址為:
xml:http://api.t.sina.com.cn/short_url/shorten.xml
json:http://api.t.sina.com.cn/short_url/shorten.json
請求方式:GET
請求參數:
source:應用的appkey
url_long:需要轉換的長鏈接
舉個例子
返回內容為:
<urls> <url> <url_short>http://t.cn/zWXySpZ</url_short> <url_long>http://www.cnblogs.com/e241138</url_long> <type>0</type> </url> </urls>
返回內容為:
[{"url_short":"http://t.cn/zWXySpZ","url_long":"http://www.cnblogs.com/e241138","type":0}]
--------------------------------------分隔線(3月15日更新)-----------------------------------------------------------
新浪更新后的長網址轉短網址官方API文檔:http://open.weibo.com/wiki/2/short_url/shorten
調用地址:https://api.weibo.com/2/short_url/shorten.json
請求方式:GET
請求參數:
- access_token: 授權后獲得
- url_long: 待轉換的長地址
返回結果:
{ "urls": [ { "url_short": "http://t.cn/h4DwT1", "url_long": "http://finance.sina.com.cn/", "type": 0, "result": "true" } ] }
注意:每次使用時都需要access_token,而access_token是需要登錄后授權才能得到的。如果你想做一個短網址轉換的應用,肯定不能要求用戶先登錄微博、授權、然后才能使用你的功能,這樣用戶體驗太差。你可以在服務器端用個測試帳號定期授權來獲取access_token,這樣就不需要用戶登錄微博授權了,用戶可以直接輸入長網址,獲取轉換后的短網址。
關於如何授權獲取access token,請參考這篇博文:http://www.cnblogs.com/e241138/archive/2013/03/15/sina-weibo-oauth-access_token.html