接口地址:https://api.thecatapi.com/v1/images/search |
---|
返回格式:json |
请求方式:get |
请求示例:https://api.thecatapi.com/v1/images/search?limit=1 |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
limit | int | 选填 | 要返回的图片数 |
page | int | 选填 | 页码 |
order | int | 选填 | 按照上传日期排序 |
has_breeds | int | 选填 | 是否包含猫品种信息 |
breed_ids | string | 选填 | 品种的ID |
category_ids | string | 选填 | 品种的ID |
sub_id | int | 选填 | 过滤具有上传时使用的值的图像sub_id |
名称 | 类型 | 说明 |
---|---|---|
url | string | 图片链接 |
width | int | 宽度 |
height | int | 图片高度 |
[{
"id": "MTgxNTAxOA",
"url": "https://cdn2.thecatapi.com/images/MTgxNTAxOA.jpg",
"width": 560,
"height": 443
}]
错误码 | 说明 |
---|---|
- | - |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2023/06/05 14:26
*/
class freeApi
{
private $apiUrl;
public function __construct()
{
$this->apiUrl = 'https://api.thecatapi.com/v1/images/search?limit=1';
}
/**
* 获取结果
* @return array
*/
public function getResult()
{
return file_get_contents($this->apiUrl);
}
}
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
const (
APIURL = "https://api.thecatapi.com/v1/images/search?limit=1"
)
func main() {
queryUrl := fmt.Sprintf("%s",APIURL)
resp, err := http.Get(queryUrl)
if err != nil {
log.Println(err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}