iceqi/pexels

www.pexels.com的Pexels API客户端

0.1.3 2016-11-22 18:17 UTC

This package is auto-updated.

Last update: 2024-09-04 16:35:00 UTC


README

Scrutinizer Code Quality Build Status Latest Stable Version Total Downloads License

安装

使用Composer安装Pexels API客户端。

"require": {
    "glooby/pexels": "~0.1"
},

使用方法

通过传入API令牌作为参数创建Pexels API客户端的实例。

$pexels = new \Glooby\Pexels\Client("xxxxx");

执行搜索,响应以数组形式返回

$response = $pexels->search('london');

遍历照片并显示它们

$images = json_decode($pexels->search('london')->getBody())->images;
foreach ($images as $image) {
 echo "<img src='{$image->src->small}' width='{$image->width}' heigth='{$image->height}'>"
}

示例响应

{
   "total_results":6,
   "page":1,
   "per_page":15,
   "photos":[  
      {  
         "id":57456,
         "width":4000,
         "height":3000,
         "url":"https://www.pexels.com/photo/brown-rocky-mountain-painting-57456/",
         "photographer":"Pixabay",
         "src":{  
            "original":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456.jpeg",
            "large":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-large.jpeg",
            "medium":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-medium.jpeg",
            "small":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-small.jpeg",
            "portrait":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-portrait.jpeg",
            "square":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-square.jpeg",
            "landscape":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-landscape.jpeg",
            "tiny":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-tiny.jpeg"
         }
      }
   ]
}

www.glooby.com www.glooby.se