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/passwordpair, 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
urlto shorten - optional
keywordandtitlefor custom short URLs - output
format: either "jsonp", "json", "xml" or "simple"
- the
- With action = "expand" :
- the
shorturlto expand (can be either 'abc' or 'http://site/abc') - output
format: either "jsonp", "json", "xml" or "simple"
- the
- With action = "url-stats" :
- the
shorturlfor 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设计原则
前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博文同时也参考了其他一些文章,相关地址会在后面贴出来.很难做到 ...
随机推荐
- PHP 快速排序算法详解
备注:下面转载的快速排序算法有bug,数组中重复值会被删除,修改后如下: function quickSort($arr){ //递归出口 if(!isset($arr[1])){ return $a ...
- Spring的模块组成
Spring的模块组成 1.核心容器:核心容器提供 Spring 框架的基本功能(Spring Core).核心容器的主要组件是 BeanFactory,它是工厂模式的实现. BeanFactory ...
- [xsy2913]enos
题意:一棵树,点有$0,1,2$三种颜色,支持路径修改颜色和查询点所在同色连通块的大小 lcm太可怕了,于是去问了sk,得到一个优质做法 考虑lct维护子树信息,$vs_{x,i}$为$x$的虚儿子中 ...
- vue 组件开发 props 验证
使用props 在Vue中父组件向子组件中传送数据是通过props实现的,一个简单的使用props的例子: <!DOCTYPE html> <html> <head> ...
- TeamViewer运行在Windows Server 2008下连接时错误提示:正在初始化显示参数
这个是使用远程桌面安装和使用Teamviewer的问题,解决方法: 实际上安装完成后TeamViewer有两个ID,一个是个人ID(就是上面卡住的780 567 914),另一个是服务器ID,我们通过 ...
- ios 得到目录大小 进率是1000
- (CGFloat)folderSizeAtPath:(NSString *) folderPath { NSFileManager * manager = [NSFileManager d ...
- window api 监控
http://pnig0s1992.blog.51cto.com/393390/704189
- HDU4548+筛素数
先筛出素数,再筛出美素数. 简单题. /* 筛素数 */ #include<stdio.h> #include<string.h> #include<stdlib.h&g ...
- 如何更改linux文件目录拥有者及用户组
查看用户和组 1 首先对于经验操作之前,我们先看下当前系统下的用户和组.whoami 查看当前登陆用户 2 Passwd文件存储当前系统所有用户,而组文件/etc/group记录. 3 一个用户可 ...
- python笔记28-lxml.etree爬取html内容
前言 本篇继续lxml.etree学习,在线访问接口,通过接口返回的html,解析出想要的text文本内容 环境准备: python 3.6 lxml requets 定位目标 爬取我的博客首页htt ...