YOURLS' API
YOURLS' API
特征
生成或获取现有的短URL,带有顺序关键字或自定义关键字
获取一些关于你的链接的统计信息:点击链接,点击最少的链接,最新链接
输出格式:JSON、XML或简单的原始文本
Authentify或者用户名/密码或使用安全密码机制
Usage
You need to send parameters to http://your-own-domain-here.com/yourls-api.php
either via GET
or POST
(remember to URL encode parameters if via GET). These parameters are:
你需要发送参数 http://your-own-domain-here.com/yourls-api.php 通过GET或POST(记住URL编码的参数,如果通过获得)。这些参数是:
一个有效的用户名/密码对,或您的签名(见文章的API请求)
请求的操作:“URL缩短”(得到一个短链接的URL),“扩大”(得到一个URL缩短长的URL),URL的状态”(获得一个短网址统计),“统计”(获取你的链接属性)或“数据库属性”(获得全球链接和点击- A valid
username
/password
pair, or yoursignature
(see Passwordless API requests) - The requested
action
: "shorturl" (get short URL for a link), "expand" (get long URL of a shorturl), "url-stats" (get stats about one short URL), "stats" (get stats about your links) or "db-stats" (get global link and click count) - With action = "shorturl" :
- the
url
to shorten - optional
keyword
andtitle
for custom short URLs - output
format
: either "jsonp", "json", "xml" or "simple"
- the
- With action = "expand" :
- the
shorturl
to expand (can be either 'abc' or 'http://site/abc') - output
format
: either "jsonp", "json", "xml" or "simple"
- the
- With action = "url-stats" :
- the
shorturl
for which to get stats (can be either 'abc' or 'http://site/abc') - output
format
: either "jsonp", "json" or "xml"
- the
- With action = "stats" :
- the
filter
: either "top", "bottom" , "rand" or "last" - the
limit
(maximum number of links to return) - output
format
: either "jsonp", "json" or "xml"
- the
- With action = "db-stats" :
- output
format
: either "jsonp", "json" or "xml"
- output
Sample requests
Example of a GET request with Javascript (using jQuery) to shorten a URL
var api_url = 'http://sho.rt/yourls-api.php';
var response = $.get( api_url, {
username: "your_username",
password: "your_password",
action: "shorturl",
format: "json",
url: "http://ozh.org/"
},
// 回调函数,它将处理服务器响应
function( data) {
// 现在用数据做一些事情,例如显示新的短URL
alert(data.shorturl);
}
);
php POST 请求扩展短URL的示例 Example of a POST request with PHP to expand a short URL
<?php
$username = 'your_username';
$password = 'your_password';
$api_url = 'http://sho.rt/yourls-api.php'; // Init the CURL session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
curl_setopt($ch, CURLOPT_POST, 1); // This is a POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, array( // Data to POST
'shorturl' => 'ozh',
'format' => 'json',
'action' => 'expand',
'username' => $username,
'password' => $password
)); // Fetch and return content
$data = curl_exec($ch);
curl_close($ch); // Do something with the result. Here, we echo the long URL
$data = json_decode( $data );
echo $data->longurl;
Sample returns
Sample return in JSON format for the shorturl
action
{
"url": {
"keyword": "ozh",
"url": "http:\/\/ozh.org",
"title": "Ozh RICHARD \u00ab ozh.org",
"date": "2014-10-24 16:01:39",
"ip": "127.0.0.1"
},
"status": "success",
"message": "http:\/\/ozh.org added to database",
"title": "Ozh RICHARD \u00ab ozh.org",
"shorturl": "http:\/\/sho.rt\/1f",
"statusCode": 200
}
Sample return in XML format for the expand
action
<result>
<keyword>ozh</keyword>
<shorturl>http://sho.rt/ozh</shorturl>
<longurl>http://ozh.org/</longurl>
<message>success</message>
<statusCode>200</statusCode>
</result>
Sample file
There's a sample PHP file included that serves as an example on how to play with the API
Expand the API
You can easily implement custom API actions with a plugin. See the plugin list for examples.
YOURLS' API的更多相关文章
- 用yourls 搭建短链接地址服务
最近工作中遇到一个需求,将app下载地址变成短链接进行推广,索性就研究了下yourls . 发现这个玩意功能挺强大的,不但可以批量生成自己的短地址,还可以管理,统计每个短地址点击数量,还可以提供api ...
- 使用基于 PHP 的开源软件 YOURLS 搭建短链接地址服务
使用基于 PHP 的开源软件 YOURLS搭建 系统配置 php7.1+mysql5.7+nginx 下载源代码 git clone https://github.com/YOURLS/YOURLS. ...
- 干货来袭-整套完整安全的API接口解决方案
在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...
- 12306官方火车票Api接口
2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...
- 几个有趣的WEB设备API(二)
浏览器和设备之间还有很多有趣的接口, 1.屏幕朝向接口 浏览器有两种方法来监听屏幕朝向,看是横屏还是竖屏. (1)使用css媒体查询的方法 /* 竖屏 */ @media screen and (or ...
- html5 canvas常用api总结(三)--图像变换API
canvas的图像变换api,可以帮助我们更加方便的绘画出一些酷炫的效果,也可以用来制作动画.接下来将总结一下canvas的变换方法,文末有一个例子来更加深刻的了解和利用这几个api. 1.画布旋转a ...
- JavaScript 对数据处理的5个API
JavaScript对数据处理包括向上取整.向下取整.四舍五入.固定精度和固定长度5种方式,分别对应ceil,floor,round,toFixed,toPrecision等5个API,本文将对这5个 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
- javascript的api设计原则
前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博文同时也参考了其他一些文章,相关地址会在后面贴出来.很难做到 ...
随机推荐
- kotlin 视频
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
- java设计模式(五)责任链模式
很多对象有每个对象对其下家的引用而连接起来形成一条链,请求在这条链上传递,直到链上某个对象决定处理此请求,应用场景如单位审批流程等. 要点:1)抽象处理者角色:定义处理请求接口及设定下家引用 2 ...
- Java Maven:spring boot + Mybatis连接MySQL,通用mapper的增删改查,映射实现多表查询
1. MySQL自带库test添加表user.role 角色表role 用户表user 2. 添加依赖,配置属性 相关依赖:百度即可,此处略 application.properties spring ...
- 洛谷P2657 Loj10165 SCOI2009 windy数
题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数? 输入输出格式 输 ...
- tyvj 1044 数字三角形 记忆化搜索
数字三角形 Time Limit: 1 Sec Memory Limit: 162 MB 题目连接 http://www.tyvj.cn/p/1044 Description 示出了一个数字三角形. ...
- LNMP环境下打击那搭建Bugfree
说明: LNMP: L=linx;N= Nginx:M=MySQL:p=PHP 本文分四部分进行讲解说明: 1.Nginx的搭建:2.php-fpm安装配置:3.源码安装Mysql5.6版本的数据库: ...
- linux命令-每天一点进步
2018-05-28 1.yum install -y,这里的-y表示,在安装软件的过程中,无需用户输入yes or no,默认yes 2../sbin/nginx -s reload,重启nginx ...
- WordPress Permissions Update Error [RESOLVED]
Recently I ran into an issue where an installation of WordPress that had never had any issues updati ...
- 怎样在MyEclipse上耍Chrome
近期在忙着期末大作业,所以Windows App和算法的专栏都没有更了,随后这几天都会陆续開始更新的,欢迎大家的关注啦-- 在写期末大作业的时候遇到一个问题.一个新的特性在MyEclipse自带的浏览 ...
- Office Word等双击空白处的“隐藏的模块中的编译错误:MTW5”解决
Microsoft Visual Basic for Applications 隐藏的模块中的编译错误:MTW5. ...