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

  1. var api_url = 'http://sho.rt/yourls-api.php';
  2. var response = $.get( api_url, {
  3. username: "your_username",
  4. password: "your_password",
  5. action: "shorturl",
  6. format: "json",
  7. url: "http://ozh.org/"
  8. },
  9. // 回调函数,它将处理服务器响应
  10. function( data) {
  11. // 现在用数据做一些事情,例如显示新的短URL
  12. alert(data.shorturl);
  13. }
  14. );

php  POST  请求扩展短URL的示例  Example of a POST request with PHP to expand a short URL

  1. <?php
  2. $username = 'your_username';
  3. $password = 'your_password';
  4. $api_url = 'http://sho.rt/yourls-api.php';
  5. // Init the CURL session
  6. $ch = curl_init();
  7. curl_setopt($ch, CURLOPT_URL, $api_url);
  8. curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result
  9. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
  10. curl_setopt($ch, CURLOPT_POST, 1); // This is a POST request
  11. curl_setopt($ch, CURLOPT_POSTFIELDS, array( // Data to POST
  12. 'shorturl' => 'ozh',
  13. 'format' => 'json',
  14. 'action' => 'expand',
  15. 'username' => $username,
  16. 'password' => $password
  17. ));
  18. // Fetch and return content
  19. $data = curl_exec($ch);
  20. curl_close($ch);
  21. // Do something with the result. Here, we echo the long URL
  22. $data = json_decode( $data );
  23. echo $data->longurl;

Sample returns

Sample return in JSON format for the shorturl action

  1. {
  2. "url": {
  3. "keyword": "ozh",
  4. "url": "http:\/\/ozh.org",
  5. "title": "Ozh RICHARD \u00ab ozh.org",
  6. "date": "2014-10-24 16:01:39",
  7. "ip": "127.0.0.1"
  8. },
  9. "status": "success",
  10. "message": "http:\/\/ozh.org added to database",
  11. "title": "Ozh RICHARD \u00ab ozh.org",
  12. "shorturl": "http:\/\/sho.rt\/1f",
  13. "statusCode": 200
  14. }

Sample return in XML format for the expand action

  1. <result>
  2. <keyword>ozh</keyword>
  3. <shorturl>http://sho.rt/ozh</shorturl>
  4. <longurl>http://ozh.org/</longurl>
  5. <message>success</message>
  6. <statusCode>200</statusCode>
  7. </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. Mistakes(Updating)

    1.当调试时发现无法正常调用函数时,检查是否发生爆栈 对于每个栈仅有4MB的空间,开int只能开大约5*10^5. 大数组一定要开全局变量 2.当long long=int*int时会爆int,一定要 ...

  2. 【SPFA判断负环】BZOJ1715- [Usaco2006 Dec]Wormholes 虫洞

    [题目大意] 判断一张图中是否存在负环. [思路] dfs版SPFA. #include<bits/stdc++.h> using namespace std; struct edge { ...

  3. Sublime Text2 默认语言(windows/unix)设置,Sublime插件大全

    Sublime默认系统语言设置 Sublime Text 2默认使用的就是UTF8,这个UTF8模式使用的是不带BOM的,如果要修改这个配置,到Perference->Settings-User ...

  4. ROS知识(9)----安装Turtlebot2和远程控制Turtlebot2

    安装turtlebot2,场景为:turtlebot2上搭载着一台电脑主机A,该电脑作为主机Master,有自带的电源和3D传感器,roscore在该台机器上启动.pc电脑远程连接A,和A通讯,pc不 ...

  5. java的(PO,VO,TO,BO,DAO,POJO)解释1

    java的(PO,VO,TO,BO,DAO,POJO)解释  O/R Mapping 是 Object Relational Mapping(对象关系映射)的缩写.通俗点讲,就是将对象与关系数据库绑定 ...

  6. mysql ga rc beta alpha区别

    alpha  暗示这是一个以展示新特性为目的的版本,存在比较多的不稳定因素,还会向代码中添加新新特性 beta 以后的beta版.发布版或产品发布中,所有API.外部可视结构和SQL命令列均不再更改, ...

  7. HEVC 实时编码720P不是梦!

    最近很少光顾我的博客, 因为一直很忙! 目前我的HEVC在i5机子上720P编码速度单核达到2~3帧每秒! 多核的话离线实时编码已经不是问题! 现在问题是在线实时编码还差那么一点! 在容忍一定低延迟下 ...

  8. 关于TFS2010 远程无法创建团队项目的若干问题总结

    今天遇到一个TFS的问题,折腾了好几个小时,故将其记录,给有遇到类似问题的朋友一些参考. 1.本文前提:服务器端只安装了TFS2010,本地没有安装Visual Studio 2010,因此不能在服务 ...

  9. 23LINQ运算符返回其它类型实例汇总

      IEnumerable<T>返回其它集合类型 ToArray() ToList() ToDictionary() ToLookUp()     返回集合中的元素 □ ElementAt ...

  10. IOS中为tableViewCell增加右侧标记(选中或者更多)

    if ([self.selectWys containsObject:[self.initCitys objectAtIndex:indexPath.row]]) { tvCell.accessory ...