| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #!/usr/bin/env node
- /** 验证 TikHub 分享链接解析 + 视频评论 + 用户主页 endpoint */
- const fs = require('fs');
- const path = require('path');
- const os = require('os');
- const https = require('https');
- const TOKEN = JSON.parse(fs.readFileSync(
- path.join(os.homedir(), '.openclaw', 'skills', 'xiaohongshu-search-notes', 'api-config.json'),
- 'utf-8'
- )).endpoint.headers.Authorization.replace(/^Bearer\s+/, '');
- function req(hostname, pathUrl) {
- return new Promise((resolve) => {
- const r = https.request({
- hostname, path: pathUrl, method: 'GET',
- headers: { Authorization: `Bearer ${TOKEN}`, Accept: 'application/json' },
- }, (res) => {
- const chunks = [];
- res.on('data', (c) => chunks.push(c));
- res.on('end', () => resolve({ status: res.statusCode, body: Buffer.concat(chunks).toString('utf-8') }));
- });
- r.on('error', (e) => resolve({ status: 0, body: e.message }));
- r.setTimeout(30000, () => { r.destroy(); resolve({ status: 0, body: 'timeout' }); });
- r.end();
- });
- }
- const SHARE_LINKS = [
- { id: 'liver', url: 'https://v.douyin.com/BMklXPTyiUM/' },
- { id: 'probiotic', url: 'https://v.douyin.com/1eV76OP0FNM/' },
- { id: 'monkey', url: 'https://v.douyin.com/C3mMbhRYKHw/' },
- ];
- (async () => {
- for (const item of SHARE_LINKS) {
- console.log(`\n=== ${item.id} ===`);
- console.log(`share_url = ${item.url}`);
- // 1) share url → video
- const r1 = await req('api.tikhub.io',
- `/api/v1/douyin/app/v3/fetch_one_video_by_share_url?share_url=${encodeURIComponent(item.url)}`);
- console.log(`[1/resolve] status=${r1.status}`);
- let aweme_id, sec_uid;
- try {
- const j = JSON.parse(r1.body);
- if (j.code === 200 && j.data) {
- const info = j.data.aweme_detail || j.data.aweme_info || j.data;
- aweme_id = info.aweme_id;
- sec_uid = info.author?.sec_uid;
- console.log(` aweme_id = ${aweme_id}`);
- console.log(` author = ${info.author?.nickname}`);
- console.log(` desc = ${String(info.desc || '').slice(0, 80).replace(/\s+/g, ' ')}`);
- console.log(` stats = digg:${info.statistics?.digg_count} comment:${info.statistics?.comment_count} share:${info.statistics?.share_count} play:${info.statistics?.play_count}`);
- } else {
- console.log(` ERR code=${j.code} msg=${j.message || j.message_zh}`);
- console.log(` body: ${r1.body.slice(0, 300)}`);
- }
- } catch (e) {
- console.log(` PARSE ERR: ${e.message}`);
- console.log(` body: ${r1.body.slice(0, 300)}`);
- }
- if (!aweme_id) continue;
- await new Promise((r) => setTimeout(r, 800));
- // 2) video comments
- const r2 = await req('api.tikhub.io',
- `/api/v1/douyin/app/v3/fetch_video_comments?aweme_id=${aweme_id}&cursor=0&count=20`);
- console.log(`[2/comments] status=${r2.status}`);
- try {
- const j = JSON.parse(r2.body);
- if (j.code === 200) {
- const cmts = j.data?.comments || [];
- console.log(` 评论数 = ${cmts.length}, total=${j.data?.total}, has_more=${j.data?.has_more}`);
- if (cmts[0]) {
- console.log(` [0] ${cmts[0].user?.nickname}: ${String(cmts[0].text || '').slice(0, 60)} (digg=${cmts[0].digg_count})`);
- }
- if (cmts[1]) console.log(` [1] ${cmts[1].user?.nickname}: ${String(cmts[1].text || '').slice(0, 60)}`);
- } else {
- console.log(` ERR code=${j.code} msg=${j.message_zh || j.message}`);
- }
- } catch (e) {
- console.log(` PARSE ERR: ${e.message}`);
- }
- if (!sec_uid) continue;
- await new Promise((r) => setTimeout(r, 800));
- // 3) user post videos
- const r3 = await req('api.tikhub.io',
- `/api/v1/douyin/app/v3/fetch_user_post_videos?sec_user_id=${encodeURIComponent(sec_uid)}&max_cursor=0&count=10`);
- console.log(`[3/user_posts] status=${r3.status}`);
- try {
- const j = JSON.parse(r3.body);
- if (j.code === 200) {
- const vids = j.data?.aweme_list || [];
- console.log(` 作者作品 = ${vids.length}, has_more=${j.data?.has_more}`);
- vids.slice(0, 3).forEach((v, i) => {
- console.log(` [${i}] digg:${v.statistics?.digg_count} comment:${v.statistics?.comment_count} | ${String(v.desc || '').slice(0, 50)}`);
- });
- } else {
- console.log(` ERR code=${j.code} msg=${j.message_zh || j.message}`);
- }
- } catch (e) {
- console.log(` PARSE ERR: ${e.message}`);
- }
- await new Promise((r) => setTimeout(r, 800));
- // 4) user profile
- const r4 = await req('api.tikhub.io',
- `/api/v1/douyin/app/v3/handler_user_profile?sec_user_id=${encodeURIComponent(sec_uid)}`);
- console.log(`[4/user_profile] status=${r4.status}`);
- try {
- const j = JSON.parse(r4.body);
- if (j.code === 200) {
- const u = j.data?.user || j.data;
- console.log(` nickname = ${u?.nickname}, 粉丝 = ${u?.follower_count}, 作品 = ${u?.aweme_count}, 签名 = ${String(u?.signature || '').slice(0, 50)}`);
- } else {
- console.log(` ERR code=${j.code} msg=${j.message_zh || j.message}`);
- }
- } catch (e) {
- console.log(` PARSE ERR: ${e.message}`);
- }
- }
- })();
|