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 your signature (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 and title for custom short URLs
    • output format: either "jsonp""json""xml" or "simple"
  • With action = "expand" :
    • the shorturl to expand (can be either 'abc' or 'http://site/abc')
    • output format: either "jsonp""json""xml" or "simple"
  • 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"
  • 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"
  • With action = "db-stats" :
    • output format: either "jsonp""json" or "xml"

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的更多相关文章

  1. 用yourls 搭建短链接地址服务

    最近工作中遇到一个需求,将app下载地址变成短链接进行推广,索性就研究了下yourls . 发现这个玩意功能挺强大的,不但可以批量生成自己的短地址,还可以管理,统计每个短地址点击数量,还可以提供api ...

  2. 使用基于 PHP 的开源软件 YOURLS 搭建短链接地址服务

    使用基于 PHP 的开源软件 YOURLS搭建 系统配置 php7.1+mysql5.7+nginx 下载源代码 git clone https://github.com/YOURLS/YOURLS. ...

  3. 干货来袭-整套完整安全的API接口解决方案

    在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...

  4. 12306官方火车票Api接口

    2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...

  5. 几个有趣的WEB设备API(二)

    浏览器和设备之间还有很多有趣的接口, 1.屏幕朝向接口 浏览器有两种方法来监听屏幕朝向,看是横屏还是竖屏. (1)使用css媒体查询的方法 /* 竖屏 */ @media screen and (or ...

  6. html5 canvas常用api总结(三)--图像变换API

    canvas的图像变换api,可以帮助我们更加方便的绘画出一些酷炫的效果,也可以用来制作动画.接下来将总结一下canvas的变换方法,文末有一个例子来更加深刻的了解和利用这几个api. 1.画布旋转a ...

  7. JavaScript 对数据处理的5个API

    JavaScript对数据处理包括向上取整.向下取整.四舍五入.固定精度和固定长度5种方式,分别对应ceil,floor,round,toFixed,toPrecision等5个API,本文将对这5个 ...

  8. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  9. javascript的api设计原则

    前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博文同时也参考了其他一些文章,相关地址会在后面贴出来.很难做到 ...

随机推荐

  1. Metasploit小技巧

    meterpreter > 进入meterpreter之后即可进行一些相关木马操作了,下面是正式本章内容 首先可以查看帮助文档,命令“help”,挑常用操作来讲↓↓↓ ------------- ...

  2. hdu 4540 dp

    题意: 假设: 1.每一个时刻我们只能打一只地鼠,并且打完以后该时刻出现的所有地鼠都会立刻消失: 2.老鼠出现的位置在一条直线上,如果上一个时刻我们在x1位置打地鼠,下一个时刻我们在x2位置打地鼠,那 ...

  3. the elements of computing systems 的读书笔记2

    懒癌发作,本来计划是两到三天就一个unit的,没想到一直拖到今天才完成第二部分(6-8章). 第6章,介绍了hack汇编到二进制,也就是用翻译到01来表示.从课后习题来看,这一章目的就是设计一个程序( ...

  4. PIVOT函数与UNPIVOT函数的运用

    PIVOT用于将行转为列,完整语法如下: TABLE_SOURCE PIVOT( 聚合函数(value_column) FOR pivot_column IN(<column_list>) ...

  5. C# 传统的ToString

    C# 传统的ToString DataRow dr=item; var str=dr["Name"]; str.ToString();//dr["Name"]= ...

  6. Xcode 几个图标解释

    File.让您指定串联图的常规信息. Quick Help.提供有关对象的实用文稿. Identity.让您指定对象的自定类并定义其辅助功能属性. Attributes.让您自定对象的可视化属性. S ...

  7. JTAG Pinouts

    http://www.jtagtest.com/pinouts/ Pinouts ARM-20 (used with almost all ARM-based microcontrollers) AR ...

  8. MySQL性能诊断与调优 转

    http://www.cnblogs.com/preftest/ http://www.highperfmysql.com/     BOOK LAMP 系统性能调优,第 3 部分: MySQL 服务 ...

  9. OPC服务器开发浅谈 — 服务器模型(转)

    这里主要讨论的是OPC Data Access 2.0服务器的开发,在掌握了这个最常用的OPC服务器开发之后,对其它类型的OPC服务器,如A&E.HDA等就可以触类旁通了. 一个OPC服务器的 ...

  10. pytest文档17-fixture之autouse=True

    前言 平常写自动化用例会写一些前置的fixture操作,用例需要用到就直接传该函数的参数名称就行了.当用例很多的时候,每次都传这个参数,会比较麻烦. fixture里面有个参数autouse,默认是F ...