分类 默认 下的文章

[article id="1643"]

根据 Cloudflare Workers 获取API 拉取的时候有些慢,所以使用php 获取到json 数据并保存在本地,通过计划任务定时生成.

<?php
$userId = '110711427149362311'; //改为自己的
$instance = 'jiong.us'; //改为自己的
$baseUrl = 'https://' . $instance . '/api/v1/accounts/' . $userId . '/statuses';
$limit = 20; // Maximum limit per page
$toots = [];

for ($i = 0; $i < 25; $i++) { // 25 pages * 40 toots per page = 1000 toots
    $ch = curl_init();
    $url = $baseUrl . '?limit=' . $limit;

    if (isset($lastId)) {
        $url .= '&max_id=' . $lastId;
    }

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    //curl_setopt($ch, CURLOPT_HTTPHEADER, [
    //    'Authorization: Bearer ' . $accessToken
    //]);

    $response = curl_exec($ch);
    curl_close($ch);

    $data = json_decode($response, true);

    if (empty($data)) {
        break;
    }

    foreach ($data as $toot) {
        if (!isset($toot['reblog']) && !isset($toot['in_reply_to_id'])) {
            $toots[] = $toot;
        }
    }

    $lastId = end($data)['id'];
}

// Now $toots contains up to 1000 toots
$jsonData = json_encode($toots, JSON_PRETTY_PRINT);
file_put_contents('toot.json', $jsonData);
?>

保存为toot.php, 访问 toot.php 则会在同级目录生成 toot.json.

创建一个定时任务定时访问toot.php


使用API创建一个应用

curl -X POST 'https://your.instance.url/api/v1/apps' \ 
  -H 'Content-Type:application/json' \
  -d '{
      "client_name": "memos",
      "redirect_uris": "urn:ietf:wg:oauth:2.0:oob",
      "scopes": "read"
    }'

得到"client_id"和"client_secret"

{
    "id": "01MAXW228JRT327ACDW2MVQCR6",
    "name": "memos",
    "redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
    "client_id": "01D9XG149GN5RTEWWQE5MDPA",
    "client_secret": "8799e15b-5978-4367-ba51-fd171fbb4d"
}

授权应用

访问 https://your.instance.url/oauth/authorize?client_id=your_new_client_id-id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code

点击通过

得到了一个code,类似

NDEYYZBKOTQTYTCWYI0ZMZKYLWE5OTYTZDHKMTG2MDQ3YJA

获得access token

用上面获取的"client_id":,"client_secret","code"执行

curl -X POST 'https://your.instance.url/oauth/token' \
  -H 'Content-Type:application/json' 
  -d '{
      "redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
      "client_id": "01D9XG149GN5RTEWWQE5MDPA",
      "client_secret": "8799e15b-5978-4367-ba51-fd171fbb4d",
      "grant_type": "authorization_code",
      "code": "NDEYYZBKOTQTYTCWYI0ZMZKYLWE5OTYTZDHKMTG2MDQ3YJA"
    }'

获取access_token

{
    "access_token": "MJRJYJMXZGMTMGNJMC0ZYZQ0LWIZYTITZTAZMTUZNDNKYMJ1",
    "created_at": 1716722670,
    "scope": "read",
    "token_type": "Bearer"
}

通过Cloudflare Workers获取json数据

替换以下的{url} {id} {token}即可

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const url = "https://{url}/api/v1/accounts/{id}/statuses?limit=1000&exclude_replies=true&only_public=true&only_media=true";
  const init = {
    method: "GET",
    headers: {
      "content-type": "application/json;charset=UTF-8",
      "User-Agent": "Node.js/v14.15.1",
      "Authorization": "Bearer {token}" // Use your real token here
    }
  };

  let response = await fetch(url, init);
  const results = await response.json();

  // 构建新的响应并添加CORS头
  let corsHeaders = {
    "Access-Control-Allow-Origin": "*",  // 这将允许所有源访问,如果你想限制访问可以更改为特定的URI
    "Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS",  // 你可以根据实际需要更改这些方法
    "Access-Control-Allow-Headers": "Content-Type, Authorization, User-Agent"  // 加入你用到的其他头
  }

  let newResponse = new Response(JSON.stringify(results), {
    headers: corsHeaders
  });

  return newResponse;
}

根据API文档,此查询会默认获取30条 包括 回复 未公开的全部内容

获取最近1000条公开的未包括回复的内容

/api/v1/accounts/01MQ6Y9ZKC7TAJ7B97Q2TAMHXQ/statuses?limit=1000&exclude_replies=true&only_public=true

获取最近1000条公开的未回复的仅多媒体的内容

/api/v1/accounts/01MQ6Y9ZKC7TAJ7B97Q2TAMHXQ/statuses?limit=1000&exclude_replies=true&only_public=true&only_media=true

替换以上的API节点

演示地址
https://bbapi.ima.cm


最近去CyberPanel官方看到,版本已经到V1.6版本,且基本的功能应该算成熟。不过目前的用户也并不是很多,这个应该与官方的实际推广宣传力度有关系,当然还有很多国内用户的使用习惯,因为毕竟作为面板而言我们选择一个习惯的就可以,也没有必要使用太多的。在这篇文章中,将体验CyberPanel免费面板的安装与基本功能应用。

1、配置要求

根据官方的要求,需要服务器系统使用的Centos 7.x、Python 2.7、内存512MB、硬盘10GB以上。

2、一键安装

实测暂时支持 centos Ubuntu 其他暂不支持

sh <(curl https://cyberpanel.net/install.sh || wget -O - https://cyberpanel.net/install.sh)

可以直接一键安装最新版本。 安装完毕,看到登入地址和用户名和密码。

3、CyberPanel登入

忘记密码如何修改密码?执行

adminPass 123456789

修改为123456789
登入CyberPanel面板,我们可以选择Chinese简体中文。因为面板自带语言包的,我们登入进入后看到简体中文。看到CyberPanel面板后台,体验还是比较好的。毕竟OpenLiteSpeed团队,华人还是比较多的,所以还是有针对性的希望让中文用户使用。