tikhub.service.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { Injectable } from '@angular/core';
  2. import { FmodeParse } from "fmode-ng/core";
  3. @Injectable({
  4. providedIn: 'root'
  5. })
  6. export class TikHubService {
  7. private Parse: any;
  8. // Cloud Function IDs
  9. private readonly FUNCTIONS = {
  10. SEARCH_USER: 'BHmiTlSNA4',
  11. GET_PROFILE: 'UfDBWNeH90',
  12. GET_POSTS: 'rZ5HSTDpMm',
  13. GET_COMMENTS: '6sjEatiEN8'
  14. };
  15. constructor() {
  16. this.Parse = FmodeParse.initialize({
  17. appId: "ncloudmaster",
  18. serverURL: "https://server.fmode.cn/parse"
  19. });
  20. }
  21. /**
  22. * Search for TikTok users
  23. * @param keyword Search keyword
  24. * @param cursor Pagination cursor
  25. */
  26. async searchUsers(keyword: string, cursor: number = 0): Promise<any> {
  27. try {
  28. const result = await this.Parse.Cloud.function({
  29. id: this.FUNCTIONS.SEARCH_USER,
  30. keyword,
  31. cursor
  32. });
  33. if (result.code === 200 && result.success) {
  34. return result.data;
  35. } else {
  36. throw new Error(result.error || 'Search failed');
  37. }
  38. } catch (error) {
  39. console.error('TikHub Search Error:', error);
  40. throw error;
  41. }
  42. }
  43. /**
  44. * Get user profile details
  45. * @param uniqueId User handle (e.g. @username)
  46. */
  47. async getUserProfile(uniqueId: string): Promise<any> {
  48. try {
  49. const result = await this.Parse.Cloud.function({
  50. id: this.FUNCTIONS.GET_PROFILE,
  51. unique_id: uniqueId
  52. });
  53. if (result.code === 200 && result.success) {
  54. return result.data;
  55. } else {
  56. throw new Error(result.error || 'Get Profile failed');
  57. }
  58. } catch (error) {
  59. console.error('TikHub Profile Error:', error);
  60. throw error;
  61. }
  62. }
  63. /**
  64. * Get user posts
  65. * @param secUid User secure UID
  66. * @param count Number of posts
  67. * @param cursor Pagination cursor
  68. */
  69. async getUserPosts(secUid: string, count: number = 20, cursor: number = 0): Promise<any> {
  70. try {
  71. const result = await this.Parse.Cloud.function({
  72. id: this.FUNCTIONS.GET_POSTS,
  73. sec_user_id: secUid,
  74. count,
  75. cursor
  76. });
  77. if (result.code === 200 && result.success) {
  78. return result.data;
  79. } else {
  80. throw new Error(result.error || 'Get Posts failed');
  81. }
  82. } catch (error) {
  83. console.error('TikHub Posts Error:', error);
  84. throw error;
  85. }
  86. }
  87. /**
  88. * Get video comments
  89. * @param videoId Video ID
  90. * @param count Number of comments
  91. * @param cursor Pagination cursor
  92. */
  93. async getPostComments(videoId: string, count: number = 50, cursor: number = 0): Promise<any> {
  94. try {
  95. const result = await this.Parse.Cloud.function({
  96. id: this.FUNCTIONS.GET_COMMENTS,
  97. video_id: videoId,
  98. count,
  99. cursor
  100. });
  101. if (result.code === 200 && result.success) {
  102. return result.data;
  103. } else {
  104. throw new Error(result.error || 'Get Comments failed');
  105. }
  106. } catch (error) {
  107. console.error('TikHub Comments Error:', error);
  108. throw error;
  109. }
  110. }
  111. }