新浪短网址API接口(3月15日更新)

原文地址为: 新浪短网址API接口(3月15日更新)

新浪旧版开发文档地址: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:需要转换的长链接

举个例子

举个栗子

xml:http://api.t.sina.com.cn/short_url/shorten.xml?source=123456789&url_long=http://www.cnblogs.com/e241138

返回内容为:

<urls>
<url>
<url_short>http://t.cn/zWXySpZ</url_short>
<url_long>http://www.cnblogs.com/e241138</url_long>
<type>0</type>
</url>
</urls>

json:http://api.t.sina.com.cn/short_url/shorten.json?source=123456789&url_long=http://www.cnblogs.com/e241138

返回内容为:

[{"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

请求参数:

  1. access_token:  授权后获得
  2. 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

(如有疑问,请微博私信或发邮件)


转载请注明本文地址: 新浪短网址API接口(3月15日更新)

猜你喜欢

转载自blog.csdn.net/a13036139941/article/details/81748074