From fa532f80c979067b01de8314a6835c4699a49241 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Tue, 27 May 2025 16:15:18 +0700 Subject: [PATCH] feat: instagram standalone refresh token --- .../social/instagram.standalone.provider.ts | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts index 8c7ec559..8de6cf54 100644 --- a/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts @@ -28,14 +28,26 @@ export class InstagramStandaloneProvider ]; async refreshToken(refresh_token: string): Promise { + const { access_token } = await ( + await this.fetch( + `https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${refresh_token}` + ) + ).json(); + + const { user_id, name, username, profile_picture_url } = await ( + await this.fetch( + `https://graph.instagram.com/v21.0/me?fields=user_id,username,name,profile_picture_url&access_token=${access_token}` + ) + ).json(); + return { - refreshToken: '', - expiresIn: 0, - accessToken: '', - id: '', - name: '', - picture: '', - username: '', + id: user_id, + name, + accessToken: access_token, + refreshToken: access_token, + expiresIn: dayjs().add(59, 'days').unix() - dayjs().unix(), + picture: profile_picture_url, + username, }; }