#!/usr/bin/env node /** 排查抖音搜索返回结构 */ const fs = require('fs'); const path = require('path'); const os = require('os'); const https = require('https'); const vocToken = JSON.parse(fs.readFileSync(path.join(os.homedir(), '.openclaw', 'voc-credentials.json'), 'utf-8')).vocToken; function req(opts, body) { return new Promise((resolve, reject) => { const r = https.request(opts, (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', reject); r.setTimeout(30000, () => { r.destroy(); reject(new Error('timeout')); }); if (body) r.write(body); r.end(); }); } (async () => { const tries = [ // Try 1: current script's POST shape { name: 'POST /api/voc-social/douyin/search/fetch_general_search_v2', opts: { hostname: 'server.fmode.cn', path: '/api/voc-social/douyin/search/fetch_general_search_v2', method: 'POST', headers: { Authorization: `Bearer ${vocToken}`, 'Content-Type': 'application/json', Accept: 'application/json', }, }, body: JSON.stringify({ keyword: '乳酸菌素片', cursor: 0, sort_type: '1', publish_time: '180' }), }, // Try 2: GET with query params (like xhs) { name: 'GET /api/voc-social/douyin/search/fetch_general_search_v2?keyword=乳酸菌素片', opts: { hostname: 'server.fmode.cn', path: `/api/voc-social/douyin/search/fetch_general_search_v2?keyword=${encodeURIComponent('乳酸菌素片')}&cursor=0&sort_type=1&publish_time=180`, method: 'GET', headers: { Authorization: `Bearer ${vocToken}`, Accept: 'application/json', }, }, }, ]; for (const t of tries) { console.log(`\n=== ${t.name} ===`); try { const { status, body } = await req(t.opts, t.body); console.log(`status: ${status}`); console.log(`body[0:400]: ${body.slice(0, 400)}`); try { const j = JSON.parse(body); const keys = Object.keys(j); console.log(`JSON top keys: ${keys.join(', ')}`); if (j.data) console.log(` data type: ${Array.isArray(j.data) ? 'Array(' + j.data.length + ')' : typeof j.data}, keys: ${Array.isArray(j.data) ? '[]' : Object.keys(j.data).join(', ')}`); } catch (e) { /* ignore */ } } catch (e) { console.log(`ERROR: ${e.message}`); } await new Promise((r) => setTimeout(r, 1500)); } })();