From 35a9b1c4cf10a5707eb705c9c76ea1b0a64f4d57 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Tue, 12 Nov 2024 11:51:53 +0700 Subject: [PATCH] feat: tiktok access token fix --- .../integrations/social/tiktok.provider.ts | 95 +++++++++---------- 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts b/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts index d969d99b..4da6234f 100644 --- a/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts @@ -222,58 +222,51 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider { postDetails: PostDetails[], integration: Integration ): Promise { - try { - const [firstPost, ...comments] = postDetails; + const [firstPost, ...comments] = postDetails; - const { - data: { publish_id }, - } = await ( - await this.fetch( - 'https://open.tiktokapis.com/v2/post/publish/video/init/', - { - method: 'POST', - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - Authorization: `Bearer ${accessToken}`, - }, - body: JSON.stringify({ - post_info: { - title: firstPost.message, - privacy_level: firstPost.settings.privacy_level, - disable_duet: !firstPost.settings.duet, - disable_comment: !firstPost.settings.comment, - disable_stitch: !firstPost.settings.stitch, - brand_content_toggle: firstPost.settings.brand_content_toggle, - brand_organic_toggle: firstPost.settings.brand_organic_toggle, - }, - source_info: { - source: 'PULL_FROM_URL', - video_url: firstPost?.media?.[0]?.url!, - }, - }), - } - ) - ).json(); - - const { url, id: videoId } = await this.uploadedVideoSuccess( - integration.profile!, - publish_id, - accessToken - ); - - return [ + const { + data: { publish_id }, + } = await ( + await this.fetch( + 'https://open.tiktokapis.com/v2/post/publish/video/init/', { - id: firstPost.id, - releaseURL: url, - postId: String(videoId), - status: 'success', - }, - ]; - } catch (err) { - throw new BadBody('titok-error', JSON.stringify(err), { - // @ts-ignore - postDetails, - }); - } + method: 'POST', + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + Authorization: `Bearer ${accessToken}`, + }, + body: JSON.stringify({ + post_info: { + title: firstPost.message, + privacy_level: firstPost.settings.privacy_level, + disable_duet: !firstPost.settings.duet, + disable_comment: !firstPost.settings.comment, + disable_stitch: !firstPost.settings.stitch, + brand_content_toggle: firstPost.settings.brand_content_toggle, + brand_organic_toggle: firstPost.settings.brand_organic_toggle, + }, + source_info: { + source: 'PULL_FROM_URL', + video_url: firstPost?.media?.[0]?.url!, + }, + }), + } + ) + ).json(); + + const { url, id: videoId } = await this.uploadedVideoSuccess( + integration.profile!, + publish_id, + accessToken + ); + + return [ + { + id: firstPost.id, + releaseURL: url, + postId: String(videoId), + status: 'success', + }, + ]; } }