xiaohongshu-api.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const { callSocialGateway } = require('./voc-gateway');
  2. const VOC_SOCIAL_API_ROOT = 'https://server.fmode.cn/api/voc-social';
  3. const XIAOHONGSHU_APP_BASE_URL = `${VOC_SOCIAL_API_ROOT}/xiaohongshu/app`;
  4. class XiaohongshuApi {
  5. constructor(options = {}) {
  6. this.baseUrl = options.baseUrl || process.env.XIAOHONGSHU_API_BASE_URL || XIAOHONGSHU_APP_BASE_URL;
  7. this.token = options.token;
  8. this.fallbackToken = options.fallbackToken || '';
  9. this.headers = options.headers || {};
  10. }
  11. request(proxyPath, query) {
  12. return callSocialGateway({
  13. proxyPath,
  14. method: 'GET',
  15. query,
  16. token: this.token,
  17. fallbackToken: this.fallbackToken,
  18. baseUrl: this.baseUrl,
  19. headers: this.headers
  20. });
  21. }
  22. searchNotes({ keyword, page = 1, sort = 'popularity_descending', noteType = '_0' }) {
  23. return this.request('search_notes', {
  24. keyword,
  25. page,
  26. sort,
  27. note_type: noteType
  28. });
  29. }
  30. getNoteDetail({ noteId }) {
  31. return this.request('get_note_info', { note_id: noteId });
  32. }
  33. getNoteComments({ noteId, cursor = '' }) {
  34. return this.request('get_note_comments', { note_id: noteId, cursor });
  35. }
  36. }
  37. module.exports = {
  38. VOC_SOCIAL_API_ROOT,
  39. XIAOHONGSHU_APP_BASE_URL,
  40. XiaohongshuApi
  41. };