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. ASP.NET MVC HttpVerbs.Delete/Put Routes not firing

    原文地址: https://weblog.west-wind.com/posts/2015/Apr/09/ASPNET-MVC-HttpVerbsDeletePut-Routes-not-firing ...

  2. UVALive 5971

    Problem J Permutation Counting Dexter considers a permutation of first N natural numbers good if it ...

  3. ROS知识(6)----卸载ROS系统

    步骤方法: 1.首先卸载包 sudo apt-get purge ros-* 2.然后卸载依赖包 sudo apt-get autoremove

  4. 关于List Map Set的线程安全的问题

    常见的ArrayList  LinkedList  HashMap TreeMap LinkedHashMap HashSet TreeSet LinkedHashSet 都是线程不安全的.如果要使用 ...

  5. HOWTO: Get the command line of a process(转)

    How would you get the command line of a process? Some people have suggested that you use remote thre ...

  6. MYSQL 源代码编绎脚本

    http://blog.csdn.net/hopingwhite/article/details/5808101

  7. Geeks 一般二叉树的LCA

    不是BST,那么搜索两节点的LCA就复杂点了,由于节点是无序的. 以下是两种方法,都写进一个类里面了. 当然须要反复搜索的时候.能够使用多种方法加速搜索. #include <iostream& ...

  8. QQclient团队博客

    Windows 8 视频採集  http://impd.tencent.com/?p=25 句柄泄漏检測工具的实现原理 http://impd.tencent.com/?p=29

  9. Major GC 是清理老年代。 Full GC 是清理整个堆空间—包括年轻代和老年代。

    Major GC 是清理老年代. Full GC 是清理整个堆空间—包括年轻代和老年代.

  10. ActiveX控件开发

    VC2005从开发MFC ActiveX ocx控件到发布到.net网站的全部过程 开篇语:最近在弄ocx控件发布到asp.net网站上使用,就是用户在使用过程中,自动下载安装ocx控件.(此文章也是 ...