probe-tikhub-douyin2.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env node
  2. /** TikHub douyin web search - try variations */
  3. const fs = require('fs');
  4. const path = require('path');
  5. const os = require('os');
  6. const https = require('https');
  7. 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+/, '');
  8. function req(opts, body) {
  9. return new Promise((resolve) => {
  10. const r = https.request(opts, (res) => {
  11. const chunks = [];
  12. res.on('data', (c) => chunks.push(c));
  13. res.on('end', () => resolve({ status: res.statusCode, body: Buffer.concat(chunks).toString('utf-8') }));
  14. });
  15. r.on('error', (e) => resolve({ status: 0, body: e.message }));
  16. r.setTimeout(30000, () => { r.destroy(); resolve({ status: 0, body: 'timeout' }); });
  17. if (body) r.write(body);
  18. r.end();
  19. });
  20. }
  21. const tries = [
  22. // With full params
  23. `/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`,
  24. // Simple keyword only
  25. `/thapi/v1/douyin/web/fetch_general_search_result?keyword=${encodeURIComponent('乳酸菌素片')}`,
  26. // Try 'search' endpoint variants
  27. `/thapi/v1/douyin/web/fetch_general_search_v2?keyword=${encodeURIComponent('乳酸菌素片')}&offset=0&count=20`,
  28. // Try app/v3 with different params
  29. `/thapi/v1/douyin/app/v3/fetch_general_search_result?keyword=${encodeURIComponent('乳酸菌素片')}&offset=0&count=20`,
  30. // Try app/v1 variations
  31. `/thapi/v1/douyin/app/v1/fetch_video_search_result?keyword=${encodeURIComponent('乳酸菌素片')}&offset=0&count=20`,
  32. ];
  33. (async () => {
  34. for (const p of tries) {
  35. const { status, body } = await req({
  36. hostname: 'server.fmode.cn', path: p, method: 'GET',
  37. headers: { Authorization: `Bearer ${TOKEN}`, Accept: 'application/json' },
  38. timeout: 30000,
  39. });
  40. console.log(`[${status}] ${p.slice(0, 100)}`);
  41. console.log(` ${body.slice(0, 250).replace(/\n/g, ' ')}`);
  42. console.log('');
  43. await new Promise((r) => setTimeout(r, 800));
  44. }
  45. })();