分享 - 短网址生成接口(最新官方api)
ztj100 2025-05-26 20:19 16 浏览 0 评论
简要描述
短网址,顾名思义就是一种较短域名加动态参数组成的短地址,类似于t.cn/xxxx,url.cn/xxx。是由各大平台诸如新浪、腾讯、百度发布的短网址接口将长网址转换而来的。
应用场景
短网址的应用场景很广,譬如短信营销、邮件推广、微信营销、QQ营销、自媒体推广、渠道推广等,都会用到短网址。究其原因是在于短网址可以降低推广成本、用户记忆成本,提高用户点击率;在特定的场景下推广还能规避关键词,防止域名被拦截,隐藏真实地址等。
短网址生成接口
1、新浪最新官方接口
http://lnurl.cn/tcn-api.json?key=hd3j2ryt&url=http://www.baidu.com
2、腾讯最新官方接口
http://lnurl.cn/url-api.json?key=a1yl3piu&url=http://www.baidu.com
接口文档
1、请求方式
- POST
2、请求参数
参数
必选
类型
说明
key
是
string
注册登录获取
3、参数说明
上文提到的接口API是官方发布的公开接口,均可以直接使用,无需获取授权Key。但有请求次数限制,超出限制,接口会返回“user dose not have resource to register long term short url”。
无限制接口是需要注册获取授权Key,Key是请求接口时用来鉴别企业或者个人的唯一身份。用来做鉴权使用,请勿随意泄露。
4、请求说明
① 在线使用
只需将 “http://www.baidu.com” 换成需要缩短的长网址(要带http(s)://),然后复制整串链接前往浏览器打开即可生成。
② 请求接口
请求接口自动生成,需要接入程序中,PHP、Java、Python相关请求示例如下。
5、请求示例
PHP请求示例:
$url = 'http://www.baidu.com';
$api_url = 'http://lnurl.cn/tcn-api.json?key=hd3j2ryt&url=http://www.baidu.com;
$short_url = file_get_contents($api_url);
echo $short_url;
Java请求示例:
public static void main(String path[]) throws Exception {
URL u = new URL("http://lnurl.cn/tcn-api.json?key=hd3j2ryt&url=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请求示例:
import urllib, urllib2, sys
host = 'http://lnurl.cn'
path = '/tcn-api.json?key=hd3j2ryt'
method = 'GET'
querys = 'link=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)
补充说明:
1、请求接口时,需做urlencode处理,否则可能会导致参数丢失,短网址失败等。
2、请求接口的长网址必须要以http(s)://开头。
3、接口请求频率不能太快,正常1次/s。
常见问题:
1、长网址转换后,为什么参数丢失了?
答:因为没有做urlencode处理,导致某些特殊字符没有识别到。需要将url编码后再请求接口。
2、请求接口为什么没有返回结果?
答:有些时候接口返回数据有延迟,就会导致超时未返回。或者是因为原链接被封了。
3、生成的短网址有效期是多久?有没有访问次数限制?
答:共享接口生成的短网址是有有效期的,正式版的接口生成的所有短网址都是永久有效的。
4、短网址有没有访问限制?
此接口为新浪和腾讯官方接口,是不限制访问次数的,可以放心使用。
相关推荐
- 10条军规:电商API从数据泄露到高可用的全链路防护
-
电商API接口避坑指南:数据安全、版本兼容与成本控制的10个教训在电商行业数字化转型中,API接口已成为连接平台、商家、用户与第三方服务的核心枢纽。然而,从数据泄露到版本冲突,从成本超支到系统崩溃,A...
- Python 文件处理在实际项目中的困难与应对策略
-
在Python项目开发,文件处理是一项基础且关键的任务。然而,在实际项目中,Python文件处理往往会面临各种各样的困难和挑战,从文件格式兼容性、编码问题,到性能瓶颈、并发访问冲突等。本文将深入...
- The Future of Manufacturing with Custom CNC Parts
-
ThefutureofmanufacturingisincreasinglybeingshapedbytheintegrationofcustomCNC(ComputerNumericalContro...
- Innovative Solutions in Custom CNC Machining
-
Inrecentyears,thelandscapeofcustomCNCmachininghasevolvedrapidly,drivenbyincreasingdemandsforprecisio...
- C#.NET serilog 详解(c# repository)
-
简介Serilog是...
- Custom CNC Machining for Small Batch Production
-
Inmodernmanufacturing,producingsmallbatchesofcustomizedpartshasbecomeanincreasinglycommondemandacros...
- Custom CNC Machining for Customized Solutions
-
Thedemandforcustomizedsolutionsinmanufacturinghasgrownsignificantly,drivenbydiverseindustryneedsandt...
- Revolutionizing Manufacturing with Custom CNC Parts
-
Understandinghowmanufacturingisevolving,especiallythroughtheuseofcustomCNCparts,canseemcomplex.Thisa...
- Breaking Boundaries with Custom CNC Parts
-
BreakingboundarieswithcustomCNCpartsinvolvesexploringhowadvancedmanufacturingtechniquesaretransformi...
- Custom CNC Parts for Aerospace Industry
-
Intherealmofaerospacemanufacturing,precisionandreliabilityareparamount.Thecomponentsthatmakeupaircra...
- Cnc machining for custom parts and components
-
UnderstandingCNCmachiningforcustompartsandcomponentsinvolvesexploringitsprocesses,advantages,andcomm...
- 洞察宇宙(十八):深入理解C语言内存管理
-
分享乐趣,传播快乐,增长见识,留下美好。亲爱的您,这里是LearingYard学苑!今天小编为大家带来“深入理解C语言内存管理”...
- The Art of Crafting Custom CNC Parts
-
UnderstandingtheprocessofcreatingcustomCNCpartscanoftenbeconfusingforbeginnersandevensomeexperienced...
- Tailored Custom CNC Solutions for Automotive
-
Intheautomotiveindustry,precisionandefficiencyarecrucialforproducinghigh-qualityvehiclecomponents.Ta...
- 关于WEB服务器(.NET)一些经验累积(一)
-
以前做过技术支持,把一些遇到的问题累积保存起来,现在发出了。1.问题:未能加载文件或程序集“System.EnterpriseServices.Wrapper.dll”或它的某一个依赖项。拒绝访问。解...
你 发表评论:
欢迎- 一周热门
- 最近发表
-
- 10条军规:电商API从数据泄露到高可用的全链路防护
- Python 文件处理在实际项目中的困难与应对策略
- The Future of Manufacturing with Custom CNC Parts
- Innovative Solutions in Custom CNC Machining
- C#.NET serilog 详解(c# repository)
- Custom CNC Machining for Small Batch Production
- Custom CNC Machining for Customized Solutions
- Revolutionizing Manufacturing with Custom CNC Parts
- Breaking Boundaries with Custom CNC Parts
- Custom CNC Parts for Aerospace Industry
- 标签列表
-
- idea eval reset (50)
- vue dispatch (70)
- update canceled (42)
- order by asc (53)
- spring gateway (67)
- 简单代码编程 贪吃蛇 (40)
- transforms.resize (33)
- redisson trylock (35)
- 卸载node (35)
- np.reshape (33)
- torch.arange (34)
- npm 源 (35)
- vue3 deep (35)
- win10 ssh (35)
- vue foreach (34)
- idea设置编码为utf8 (35)
- vue 数组添加元素 (34)
- std find (34)
- tablefield注解用途 (35)
- python str转json (34)
- java websocket客户端 (34)
- tensor.view (34)
- java jackson (34)
- vmware17pro最新密钥 (34)
- mysql单表最大数据量 (35)