glooby /
pexels
www.pexels.com 的 Pexels API 客户端
0.1.4
2019-04-17 08:26 UTC
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~6.0
README
安装
使用 Composer 安装 Pexels API 客户端。
"require": { "glooby/pexels": "~0.1" },
使用方法
通过传递 API 令牌作为参数来创建 Pexels API 客户端的实例。
$pexels = new \Glooby\Pexels\Client("xxxxx");
执行搜索,响应以数组形式返回
$response = $pexels->search('london');
遍历照片并显示它们
$photos = json_decode($pexels->search('london')->getBody())->photos; foreach ($photos as $photo) { echo "<img src='{$photo->src->small}' width='{$photo->width}' heigth='{$photo->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"
}
}
]
}