Skip to content

Let's use AI to Earn!

refactor: clean up Kwai, Meta, TikTok, Twitter, and YouTube controller (#374)

nevin0b533116fd99
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/kwai/kwai.controller.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/kwai/kwai.controller.ts
index d3b9b8f8..7ca358e8 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/kwai/kwai.controller.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/kwai/kwai.controller.ts
@@ -9,8 +9,6 @@ import { KwaiService } from './kwai.service'
export class KwaiController {
constructor(private readonly kwaiService: KwaiService) {}
- // 获取页面的认证URL
- // @NatsMessagePattern('plat.kwai.auth')
@ApiDoc({
summary: 'Create Authorization Task',
body: GetAuthUrlDto.schema,
@@ -20,8 +18,6 @@ export class KwaiController {
return this.kwaiService.createAuthTask(data)
}
- // 查询认证信息
- // @NatsMessagePattern('plat.kwai.getAuthInfo')
@ApiDoc({
summary: 'Get Authorization Task Info',
body: GetAuthInfoDto.schema,
@@ -31,8 +27,6 @@ export class KwaiController {
return this.kwaiService.getAuthInfo(data.taskId)
}
- // 创建账号并设置授权Token
- // @NatsMessagePattern('plat.kwai.createAccountAndSetAccessToken')
@ApiDoc({
summary: 'Create Account and Set Access Token',
body: CreateAccountAndSetAccessTokenDto.schema,
@@ -51,8 +45,6 @@ export class KwaiController {
return res
}
- // 获取用户公开信息
- // @NatsMessagePattern('plat.kwai.getAuthorInfo')
@ApiDoc({
summary: 'Get Author Information',
body: AccountIdDto.schema,
@@ -62,8 +54,6 @@ export class KwaiController {
return this.kwaiService.getAuthorInfo(data.accountId)
}
- // 获取视频列表
- // @NatsMessagePattern('plat.kwai.getPhotoList')
@ApiDoc({
summary: 'List Published Videos',
body: GetPohotListDto.schema,
@@ -73,7 +63,6 @@ export class KwaiController {
return this.kwaiService.fetchVideoList(data.accountId, data?.cursor, data?.count)
}
- // @NatsMessagePattern('plat.kwai.accessTokenStatus')
@ApiDoc({
summary: 'Get Access Token Status',
body: AccountIdDto.schema,
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/kwai/kwai.service.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/kwai/kwai.service.ts
index a0dc24f6..40c0fa57 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/kwai/kwai.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/kwai/kwai.service.ts
@@ -157,16 +157,15 @@ export class KwaiService extends PlatformBaseService {
const taskInfo = await this.redisService.getJson<AuthTaskInfo<BilibiliAuthInfo>>(
cacheKey,
)
- if (!taskInfo || taskInfo.status !== 0 || !taskInfo.data)
+ if (!taskInfo || taskInfo.status !== 0 || !taskInfo.data) {
return { status: 0, message: '任务不存在或已完成' }
+ }
- // 延长授权时间
void this.redisService.expire(cacheKey, 60 * 3)
try {
const account = await this.addKwaiAccount(code, taskInfo.data.userId, taskInfo.spaceId)
if (account) {
- // 更新任务信息
taskInfo.status = 1
taskInfo.data['accountId'] = account.id
await this.redisService.setJson(
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/meta/meta.controller.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/meta/meta.controller.ts
index 22237f43..52a7a4fc 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/meta/meta.controller.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/meta/meta.controller.ts
@@ -109,9 +109,6 @@ export class MetaController {
})
}
- // NATS message pattern for post oauth callback
- // get access token and create account
- // @NatsMessagePattern('plat.meta.createAccountAndSetAccessToken')
@ApiDoc({
summary: 'Create Account and Set Access Token',
})
@@ -123,7 +120,6 @@ export class MetaController {
})
}
- // @NatsMessagePattern('plat.meta.facebook.page.insights')
@ApiDoc({
summary: 'Get Facebook Page Insights',
})
@@ -137,7 +133,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.facebook.post.insights')
@ApiDoc({
summary: 'Get Facebook Post Insights',
})
@@ -151,7 +146,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.facebook.page.published_posts')
@ApiDoc({
summary: 'Get Facebook Published Posts',
})
@@ -165,7 +159,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.instagram.account.info')
@ApiDoc({
summary: 'Get Instagram Account Info',
})
@@ -179,7 +172,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.instagram.account.insights')
@ApiDoc({
summary: 'Get Instagram Account Insights',
})
@@ -193,7 +185,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.instagram.post.insights')
@ApiDoc({
summary: 'Get Instagram Post Insights',
})
@@ -208,7 +199,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.threads.account.insights')
@ApiDoc({
summary: 'Get Threads Account Insights',
})
@@ -222,7 +212,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.threads.post.insights')
@ApiDoc({
summary: 'Get Threads Post Insights',
})
@@ -237,7 +226,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.facebook.page.posts')
@ApiDoc({
summary: 'Get Facebook Page Posts',
})
@@ -251,7 +239,6 @@ export class MetaController {
)
}
- // @NatsMessagePattern('plat.meta.facebook.page.post.comments')
@ApiDoc({
summary: 'Get Facebook Post Comments',
})
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/meta/meta.service.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/meta/meta.service.ts
index 2c253c9e..230582a8 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/meta/meta.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/meta/meta.service.ts
@@ -446,6 +446,12 @@ export class MetaService {
credential.access_token,
authTaskInfo.platform,
)
+ if (!userProfile) {
+ return {
+ status: 0,
+ message: 'get user profile failed',
+ }
+ }
userProfile.groupId = authTaskInfo.spaceId
if (metaOAuth2ConfigMap[authTaskInfo.platform].pageAccountURL) {
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/tiktok/tiktok.controller.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/tiktok/tiktok.controller.ts
index 6e39b6d3..b970daf1 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/tiktok/tiktok.controller.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/tiktok/tiktok.controller.ts
@@ -29,8 +29,6 @@ import { TiktokService } from './tiktok.service'
export class TiktokController {
constructor(private readonly tiktokService: TiktokService) {}
- // 获取页面的认证URL
- // @NatsMessagePattern('plat.tiktok.authUrl')
@ApiDoc({
summary: 'Get TikTok Authorization URL',
body: GetAuthUrlDto.schema,
@@ -40,8 +38,6 @@ export class TiktokController {
return await this.tiktokService.getAuthUrl(data.userId, data.scopes, data.spaceId)
}
- // 查询认证信息
- // @NatsMessagePattern('plat.tiktok.getAuthInfo')
@ApiDoc({
summary: 'Get Authorization Task Info',
body: GetAuthInfoDto.schema,
@@ -59,13 +55,11 @@ export class TiktokController {
return await this.tiktokService.getAuthUrl(query.userId, query.scopes)
}
- // 获取AccessToken,并记录到用户,给平台回调用
@ApiDoc({
summary: 'Handle Authorization Callback',
})
@Get('auth/back/:prefix/:taskId')
async getAccessToken(
- @Param('prefix') prefix: string,
@Param('taskId') taskId: string,
@Query()
query: {
@@ -96,8 +90,6 @@ export class TiktokController {
})
}
- // 创建账号并设置授权Token
- // @NatsMessagePattern('plat.tiktok.createAccountAndSetAccessToken')
@ApiDoc({
summary: 'Create Account and Set Access Token',
body: CreateAccountAndSetAccessTokenDto.schema,
@@ -115,8 +107,6 @@ export class TiktokController {
)
}
- // 刷新访问令牌
- // @NatsMessagePattern('plat.tiktok.refreshAccessToken')
@ApiDoc({
summary: 'Refresh Access Token',
body: RefreshTokenDto.schema,
@@ -129,8 +119,6 @@ export class TiktokController {
)
}
- // 撤销访问令牌
- // @NatsMessagePattern('plat.tiktok.revokeAccessToken')
@ApiDoc({
summary: 'Revoke Access Token',
body: RevokeTokenDto.schema,
@@ -140,8 +128,6 @@ export class TiktokController {
return await this.tiktokService.revokeAccessToken(data.accountId)
}
- // 获取创作者信息
- // @NatsMessagePattern('plat.tiktok.getCreatorInfo')
@ApiDoc({
summary: 'Get Creator Information',
body: AccountIdDto.schema,
@@ -151,8 +137,6 @@ export class TiktokController {
return await this.tiktokService.getCreatorInfo(data.accountId)
}
- // 初始化视频发布
- // @NatsMessagePattern('plat.tiktok.initVideoPublish')
@ApiDoc({
summary: 'Initialize Video Publish',
body: VideoPublishDto.schema,
@@ -166,8 +150,6 @@ export class TiktokController {
)
}
- // 初始化照片发布
- // @NatsMessagePattern('plat.tiktok.initPhotoPublish')
@ApiDoc({
summary: 'Initialize Photo Publish',
body: PhotoPublishDto.schema,
@@ -182,8 +164,6 @@ export class TiktokController {
)
}
- // 查询发布状态
- // @NatsMessagePattern('plat.tiktok.getPublishStatus')
@ApiDoc({
summary: 'Get Publish Status',
body: GetPublishStatusDto.schema,
@@ -196,8 +176,6 @@ export class TiktokController {
)
}
- // 上传视频文件
- // @NatsMessagePattern('plat.tiktok.uploadVideoFile')
@ApiDoc({
summary: 'Upload Video File',
body: UploadVideoFileDto.schema,
@@ -221,7 +199,6 @@ export class TiktokController {
return await this.tiktokService.publishVideoViaURL(data.accountId, data.videoUrl)
}
- // @NatsMessagePattern('plat.tiktok.user.info')
@ApiDoc({
summary: 'Get User Info',
body: UserInfoDto.schema,
@@ -231,7 +208,6 @@ export class TiktokController {
return await this.tiktokService.getUserInfo(data.accountId, data.fields)
}
- // @NatsMessagePattern('plat.tiktok.user.videos')
@ApiDoc({
summary: 'List User Videos',
body: ListUserVideosDto.schema,
@@ -246,7 +222,6 @@ export class TiktokController {
)
}
- // @NatsMessagePattern('plat.tiktok.accessTokenStatus')
@ApiDoc({
summary: 'Get Access Token Status',
body: AccountIdDto.schema,
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/twitter/twitter.controller.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/twitter/twitter.controller.ts
index bc50b409..6a57a3f9 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/twitter/twitter.controller.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/twitter/twitter.controller.ts
@@ -95,9 +95,6 @@ export class TwitterController {
return await this.twitterService.publishPost(data.accountId, data.imgUrlList, data.videoUrl, data.desc)
}
- // NATS message pattern for post oauth callback
- // get access token and create account
- // @NatsMessagePattern('plat.twitter.createAccountAndSetAccessToken')
@ApiDoc({
summary: 'Create Account and Set Access Token',
})
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/twitter/twitter.service.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/twitter/twitter.service.ts
index d310072c..f9c4bd73 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/twitter/twitter.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/twitter/twitter.service.ts
@@ -209,19 +209,24 @@ export class TwitterService extends PlatformBaseService {
}
// fetch twitter user profile
- const userProfile = await this.twitterApiService.getUserInfo(
+ const userRes = await this.twitterApiService.getUserInfo(
credential.access_token,
)
- this.logger.log(userProfile)
+ if (!userRes.data) {
+ this.logger.error(`Failed to get user profile for state: ${state}`)
+ return {
+ status: 0,
+ message: `获取用户信息失败: ${JSON.stringify(userRes.errors)}`,
+ }
+ }
- // 创建账号数据
const newAccountData = new NewAccount({
userId: authTaskInfo.userId,
type: AccountType.TWITTER,
- uid: userProfile.id,
- account: userProfile.username,
- avatar: userProfile.profile_image_url,
- nickname: userProfile.name,
+ uid: userRes.data.id,
+ account: userRes.data.username,
+ avatar: userRes.data.profile_image_url,
+ nickname: userRes.data.name,
lastStatsTime: new Date(),
loginTime: new Date(),
groupId: authTaskInfo.spaceId,
@@ -232,13 +237,13 @@ export class TwitterService extends PlatformBaseService {
authTaskInfo.userId,
{
type: AccountType.TWITTER,
- uid: userProfile.id,
+ uid: userRes.data.id,
},
newAccountData,
)
if (!accountInfo) {
this.logger.error(
- `Failed to create account for userId: ${authTaskInfo.userId}, twitterId: ${userProfile.id}`,
+ `Failed to create account for userId: ${authTaskInfo.userId}, twitterId: ${userRes.data.id}`,
)
return {
status: 0,
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/youtube/youtube.controller.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/youtube/youtube.controller.ts
index 2afa92cd..ef952b94 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/youtube/youtube.controller.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/youtube/youtube.controller.ts
@@ -113,8 +113,6 @@ export class YoutubeController {
return res
}
- // 设置授权Token
- // @NatsMessagePattern('plat.youtube.setAccessToken')
@ApiDoc({
summary: 'Set Access Token',
body: CreateAccountAndSetAccessTokenDto.schema,
@@ -126,8 +124,6 @@ export class YoutubeController {
return res
}
- // 创建账号并设置授权Token
- // @NatsMessagePattern('plat.youtube.createAccountAndSetAccessToken')
@ApiDoc({
summary: 'Create Account and Set Access Token',
body: CreateAccountAndSetAccessTokenDto.schema,
@@ -146,8 +142,6 @@ export class YoutubeController {
return res
}
- // 查询账号是否授权
- // @NatsMessagePattern('plat.youtube.isAuthorized')
@ApiDoc({
summary: 'Check Authorization Status',
body: AccountIdDto.schema,
@@ -158,7 +152,6 @@ export class YoutubeController {
return res
}
- // 刷新令牌token
@ApiDoc({
summary: 'Refresh Token via Crawler Account',
})
@@ -170,8 +163,6 @@ export class YoutubeController {
return res
}
- // 刷新令牌token
- // @NatsMessagePattern('plat.youtube.refreshToken')
@ApiDoc({
summary: 'Refresh Token',
body: AccountIdDto.schema,
@@ -182,8 +173,6 @@ export class YoutubeController {
return res
}
- // 获取视频类别
- // @NatsMessagePattern('plat.youtube.getVideoCategories')
@ApiDoc({
summary: 'Get Video Categories',
body: VideoCategoriesDto.schema,
@@ -198,8 +187,6 @@ export class YoutubeController {
return res
}
- // 获取视频列表
- // @NatsMessagePattern('plat.youtube.getVideosList')
@ApiDoc({
summary: 'Get Video List',
body: VideosListDto.schema,
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/youtube/youtube.service.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/youtube/youtube.service.ts
index f5d52267..35a5db09 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/youtube/youtube.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/youtube/youtube.service.ts
@@ -9,7 +9,7 @@ import { Readable } from 'node:stream'
import { Injectable, Logger } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
-import { AccountStatus, AccountType, AitoearnServerClientService, NewAccount } from '@yikart/aitoearn-server-client'
+import { AccountStatus, AccountType, NewAccount } from '@yikart/aitoearn-server-client'
import { AppException, ResponseCode } from '@yikart/common'
import { RedisService } from '@yikart/redis'
import axios from 'axios'
@@ -56,7 +56,6 @@ export class YoutubeService extends PlatformBaseService {
private readonly redisService: RedisService,
private readonly youtubeApiService: YoutubeApiService,
private readonly accountService: AccountService,
- private readonly serverClient: AitoearnServerClientService,
@InjectModel(OAuth2Credential.name)
private OAuth2CredentialModel: Model<OAuth2Credential>,
@@ -77,59 +76,50 @@ export class YoutubeService extends PlatformBaseService {
* 创建账号+设置授权Token
* @param taskId
* @param data
+ * @param data.code 授权码
+ * @param data.state 状态码
* @returns
*/
async createAccountAndSetAccessToken(
taskId: string,
data: { code: string, state: string },
- ) {
+ ): Promise<{ status: number, message: string, accountId?: string }> {
const { code } = data
const authTask = await this.redisService.getJson<AuthTaskInfo>(
`youtube:authTask:${taskId}`,
)
-
if (!authTask || authTask?.state !== taskId) {
this.logger.error(`无效的任务ID: ${taskId}`)
return { status: 0, message: '无效的任务ID' }
}
- try {
- // 使用授权码获取访问令牌和刷新令牌
- const params = new URLSearchParams({
- code,
- redirect_uri: `${this.webRenderBaseUrl}`,
- client_id: this.webClientId,
- grant_type: 'authorization_code',
- client_secret: this.webClientSecret,
- })
- const response = await axios.post(
- 'https://oauth2.googleapis.com/token',
- params.toString(),
- {
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
- },
- )
+ try {
+ const accessTokenRes = await this.youtubeApiService.getAccessToken(code, `${this.webRenderBaseUrl}`)
+ if (!accessTokenRes) {
+ return { status: 0, message: '获取访问令牌失败' }
+ }
const { access_token, refresh_token, expires_in, id_token }
- = response.data
+ = accessTokenRes
// 验证ID令牌以获取用户信息
- // const oauth2Client = new google.auth.OAuth2();
- // this.oauth2Client.setCredentials({ access_token });
this.initializeYouTubeClient(access_token)
+
const ticket = await this.oauth2Client.verifyIdToken({
idToken: id_token,
audience: this.webClientId,
})
+ if (!ticket) {
+ return { status: 0, message: '验证ID令牌失败' }
+ }
const payload = ticket.getPayload()
if (!payload) {
- throw new Error('Invalid ID token')
+ return { status: 0, message: 'Invalid ID token' }
}
const googleId = payload.sub
const email = payload.email || ''
const userId = authTask.userId
- // console.log('-----userId:----', userId)
// 获取YouTube频道信息,用于更新账号数据库
const accountInfo = await this.updateYouTubeAccountInfo(
userId,
@@ -192,8 +182,6 @@ export class YoutubeService extends PlatformBaseService {
60 * 3,
)
- // // 返回系统令牌
- this.logger.log('最终返回', res)
if (!res)
return { status: 0, message: '更新任务信息失败' }
return { status: 1, message: '添加账号成功', accountId: accountInfo.id }
@@ -253,7 +241,7 @@ export class YoutubeService extends PlatformBaseService {
/**
* 设置授权Token
* @param taskId
- * @param data
+ * @param code
* @returns
*/
async setAccessToken(taskId: string, code: string) {
@@ -286,7 +274,6 @@ export class YoutubeService extends PlatformBaseService {
const refresh_token = accessTokenInfo.refresh_token
const expires_in = accessTokenInfo.expires_in
const id_token = accessTokenInfo.id_token
- this.logger.log(`Youtube OAuth2 response: ${JSON.stringify(response.data)}`)
// 验证ID令牌以获取用户信息
this.initializeYouTubeClient(access_token)
const ticket = await this.oauth2Client.verifyIdToken({
@@ -349,6 +336,7 @@ export class YoutubeService extends PlatformBaseService {
/**
* 获取YouTube频道信息并更新账号数据库
* @param userId 用户ID
+ * @param email 邮箱
* @param googleId Google ID
* @param accessToken 访问令牌
* @param refreshToken 刷新令牌
@@ -453,7 +441,6 @@ export class YoutubeService extends PlatformBaseService {
accountId: string,
refreshToken: string,
): Promise<string> {
- // console.log(accountId, refreshToken)
const accessTokenInfo
= await this.youtubeApiService.refreshAccessToken(refreshToken)
if (!accessTokenInfo)
diff --git a/project/backend/apps/aitoearn-channel/src/libs/twitter/twitter.service.ts b/project/backend/apps/aitoearn-channel/src/libs/twitter/twitter.service.ts
index aa0cb0ec..e5a6efc0 100644
--- a/project/backend/apps/aitoearn-channel/src/libs/twitter/twitter.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/libs/twitter/twitter.service.ts
@@ -6,7 +6,6 @@ import {
TwitterFollowingResponse,
TwitterOAuthCredential,
TwitterRevokeAccessResponse,
- TwitterUserInfo,
TwitterUserInfoResponse,
XChunkedMediaUploadRequest,
XCreatePostRequest,
@@ -146,7 +145,7 @@ export class TwitterService {
return await this.request<TwitterRevokeAccessResponse>(url, config, { operation: 'revokeOAuthCredential' })
}
- async getUserInfo(accessToken: string): Promise<TwitterUserInfo> {
+ async getUserInfo(accessToken: string): Promise<TwitterUserInfoResponse> {
const url = `${this.apiBaseUrl}/users/me`
const config: AxiosRequestConfig = {
method: 'GET',
@@ -159,7 +158,7 @@ export class TwitterService {
},
}
const response = await this.request<TwitterUserInfoResponse>(url, config, { operation: 'getUserInfo' })
- return response.data
+ return response
}
async followUser(
diff --git a/project/backend/apps/aitoearn-channel/src/libs/youtube/youtubeApi.service.ts b/project/backend/apps/aitoearn-channel/src/libs/youtube/youtubeApi.service.ts
index 143f6cf7..8b6df1b9 100644
--- a/project/backend/apps/aitoearn-channel/src/libs/youtube/youtubeApi.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/libs/youtube/youtubeApi.service.ts
@@ -10,6 +10,7 @@ import axios from 'axios'
import { google } from 'googleapis'
import { config } from '../../config'
import {
+ AccessToken,
ChannelsList,
CommentsList,
VideosList,
@@ -53,6 +54,36 @@ export class YoutubeApiService {
return google.youtube({ version: 'v3', auth })
}
+ /**
+ * 使用授权码获取访问令牌和刷新令牌
+ * @param code 授权码
+ * @param redirectUri 重定向URI
+ * @returns 访问令牌和刷新令牌
+ */
+ async getAccessToken(code: string, redirectUri: string): Promise<AccessToken> {
+ try {
+ const params = new URLSearchParams({
+ code,
+ redirect_uri: redirectUri,
+ client_id: this.webClientId,
+ grant_type: 'authorization_code',
+ client_secret: this.webClientSecret,
+ })
+
+ const response = await axios.post('https://oauth2.googleapis.com/token', params.toString(), {
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
+ })
+ const { access_token, refresh_token, expires_in, id_token }
+ = response.data
+
+ return { access_token, refresh_token, expires_in, id_token }
+ }
+ catch (err) {
+ this.logger.error(err)
+ return null
+ }
+ }
+
/**
* 刷新用户的YouTube访问令牌
* @param refreshToken 刷新令牌
@@ -108,11 +139,12 @@ export class YoutubeApiService {
/**
* 获取频道列表
- * @param userId 用户ID
- * @param handle 频道handle
- * @param userName 用户名
- * @param id 频道ID
- * @param mine 是否查询自己的频道
+ * @param requestParams
+ * @param requestParams.userId 用户ID
+ * @param requestParams.handle 频道handle
+ * @param requestParams.userName 用户名
+ * @param requestParams.id 频道ID
+ * @param requestParams.mine 是否查询自己的频道
* @returns 频道列表
*/
async getChannelsList(requestParams: ChannelsList) {
diff --git a/project/backend/apps/aitoearn-server/src/user/login.service.ts b/project/backend/apps/aitoearn-server/src/user/login.service.ts
index de129be1..14a9c37f 100644
--- a/project/backend/apps/aitoearn-server/src/user/login.service.ts
+++ b/project/backend/apps/aitoearn-server/src/user/login.service.ts
@@ -34,6 +34,7 @@ export class LoginService implements OnModuleInit {
code,
},
subject: 'AiToEarn Verification Code',
+ from_email: '[email protected]',
})
return res
}
@@ -59,10 +60,11 @@ export class LoginService implements OnModuleInit {
subscriber_id: subscriber.id,
template_id: 6,
data:
- {
- code,
- },
+ {
+ code,
+ },
subject: 'AiToEarn Verification Code',
+ from_email: '[email protected]',
})
return res
}
@@ -87,10 +89,11 @@ export class LoginService implements OnModuleInit {
subscriber_id: subscriber.id,
template_id: 7,
data:
- {
- code,
- },
+ {
+ code,
+ },
subject: 'AiToEarn Verification Code',
+ from_email: '[email protected]',
})
return res
}