| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/env node
- /** TikHub douyin web search - try variations */
- 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(opts, body) {
- return new Promise((resolve) => {
- 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', (e) => resolve({ status: 0, body: e.message }));
- r.setTimeout(30000, () => { r.destroy(); resolve({ status: 0, body: 'timeout' }); });
- if (body) r.write(body);
- r.end();
- });
- }
- const tries = [
- // With full params
- `/thapi/v1/douyin/web/fetch_general_search_result?keyword=${encodeURIComponent('乳酸菌素片')}&offset=0&count=20&search_channel=aweme_general&sort_type=0&publish_time=0&search_source=normal_search`,
- // Simple keyword only
- `/thapi/v1/douyin/web/fetch_general_search_result?keyword=${encodeURIComponent('乳酸菌素片')}`,
- // Try 'search' endpoint variants
- `/thapi/v1/douyin/web/fetch_general_search_v2?keyword=${encodeURIComponent('乳酸菌素片')}&offset=0&count=20`,
- // Try app/v3 with different params
- `/thapi/v1/douyin/app/v3/fetch_general_search_result?keyword=${encodeURIComponent('乳酸菌素片')}&offset=0&count=20`,
- // Try app/v1 variations
- `/thapi/v1/douyin/app/v1/fetch_video_search_result?keyword=${encodeURIComponent('乳酸菌素片')}&offset=0&count=20`,
- ];
- (async () => {
- for (const p of tries) {
- const { status, body } = await req({
- hostname: 'server.fmode.cn', path: p, method: 'GET',
- headers: { Authorization: `Bearer ${TOKEN}`, Accept: 'application/json' },
- timeout: 30000,
- });
- console.log(`[${status}] ${p.slice(0, 100)}`);
- console.log(` ${body.slice(0, 250).replace(/\n/g, ' ')}`);
- console.log('');
- await new Promise((r) => setTimeout(r, 800));
- }
- })();
|