博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bit.ly 短地址转换_使用PHP创建Bit.ly短URL:API版本3
阅读量:2518 次
发布时间:2019-05-11

本文共 2119 字,大约阅读时间需要 7 分钟。

bit.ly 短地址转换

is a great URL shortening service. I love their reliability, shortness of the URL, and the information they provide about a given URL. Recently Bit.ly updated their API to version 3 so I thought I'd update my original . Here's how you can create short URLs and expand short URLs using Bit.ly.

是一个很棒的URL缩短服务。 我喜欢它们的可靠性,URL的简短性以及它们提供的有关给定URL的信息。 最近Bit.ly将他们的API更新到了版本3,所以我想我应该更新我的原始 。 这是使用Bit.ly创建短URL并扩展短URL的方法。

PHP (The PHP)

/* returns the shortened url */function get_bitly_short_url($url,$login,$appkey,$format='txt') {	$connectURL = 'http://api.bit.ly/v3/shorten?login='.$login.'&apiKey='.$appkey.'&uri='.urlencode($url).'&format='.$format;	return curl_get_result($connectURL);}/* returns expanded url */function get_bitly_long_url($url,$login,$appkey,$format='txt') {	$connectURL = 'http://api.bit.ly/v3/expand?login='.$login.'&apiKey='.$appkey.'&shortUrl='.urlencode($url).'&format='.$format;	return curl_get_result($connectURL);}/* returns a result form url */function curl_get_result($url) {	$ch = curl_init();	$timeout = 5;	curl_setopt($ch,CURLOPT_URL,$url);	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);	$data = curl_exec($ch);	curl_close($ch);	return $data;}/* get the short url */$short_url = get_bitly_short_url('https://davidwalsh.name/','davidwalshblog','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');/* get the long url from the short one */$long_url = get_bitly_long_url($short_url,'davidwalshblog','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

All you really need to is pass your appkey and login (you must sign up for their API service), the long or short URL, and the format which you'd like the result to be returned in. If you just want a simple URL with no other information, use the default "txt" format. Retrieving the XML or JSON formats will provide you more information about the URL.

您真正需要做的就是传递您的appkey和登录名(您必须注册其API服务),长或短URL以及希望返回结果的格式。如果您只想使用简单的URL没有其他信息,请使用默认的“ txt”格式。 检索XML或JSON格式将为您提供有关URL的更多信息。

Bit.ly is awesome. I mean, Twitter uses them -- what more of an endorsement would you need.

Bit.ly很棒。 我的意思是,Twitter使用它们-您还需要更多认可。

翻译自:

bit.ly 短地址转换

转载地址:http://lcpwd.baihongyu.com/

你可能感兴趣的文章
AOP面向切面编程C#实例
查看>>
AngularJs学习笔记-慕课网AngularJS实战
查看>>
数据库三大范式
查看>>
工作总结之二:bug级别、优先级别、bug状态
查看>>
访问修饰符、封装、继承
查看>>
更换pip源到国内镜像,提升pip下载速度.
查看>>
POJ 2265 Bee Maja (找规律)
查看>>
Kendo MVVM 数据绑定(七) Invisible/Visible
查看>>
[zz]kvm环境使用libvirt创建虚拟机
查看>>
bzoj1059 [ZJOI2007]矩阵游戏
查看>>
插入返回ibatis 的selectKey 实现插入数据后获得id
查看>>
vim 程序编辑器
查看>>
LIS(单调队列优化 C++ 版)(施工ing)
查看>>
刚接触Vuex
查看>>
四种加载React数据的技术对比(Meteor 转)
查看>>
Airthmetic_Approching
查看>>
操作文本文件
查看>>
公司项目的几个问题
查看>>
解决win7下打开Excel2007,报“向程序发送命令时出现问题”的错误
查看>>
Velocity快速入门教程
查看>>