随机活动
其他 官方文档
如果你不知道现在该干什么,可以用它,前提是你懂得英语
基本说明:
接口地址:https://www.boredapi.com/api/activity
返回格式:json
请求方式:get/post
请求示例:https://www.boredapi.com/api/activity
请求参数说明:
名称 类型 必填 说明
participants string 选填 活动参加人数
type string 选填 活动类型
price float 选填 活动成本的因素
accessibility float 选填 活动发生的可能性的因素,其中零是最容易达成的
返回参数说明:
名称 类型 说明
activity string 活动名称
accessibility string 活动发生的可能性
type string 活动类型
participants string 活动参加人数
price string 活动成本的因素
link string
link string 活动涉及网站
JSON返回示例:
{
    "activity": "Learn a new recipe",
    "type": "cooking",
    "participants": 1,
    "price": 0,
    "link": "",
    "key": "6553978",
    "accessibility": 0.05
}
服务级错误码参照
错误码 说明
- -
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2023/11/10 14:26
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'https://www.boredapi.com/api/activity';
    }

    /**
     * 获取结果
     * @return array
     */
    public function getResult()
    {
        return file_get_contents($this->apiUrl);
    }
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

const (
	APIURL   = "https://www.boredapi.com/api/activity"
)

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))
}