TikTok V3

This commit is contained in:
2026-07-09 18:18:17 +02:00
parent cc2522f7a4
commit 1a39593b29
3 changed files with 26 additions and 11 deletions

View File

@@ -24,7 +24,7 @@ export async function GET(request: NextRequest) {
const authUrl = new URL('https://www.tiktok.com/v2/auth/authorize/');
authUrl.searchParams.set('client_key', clientKey);
authUrl.searchParams.set('scope', 'user.info.basic,user.info.stats,video.list,video.upload,video.publish');
authUrl.searchParams.set('scope', 'user.info.basic,user.info.profile,user.info.stats,video.list,video.upload');
authUrl.searchParams.set('response_type', 'code');
authUrl.searchParams.set('redirect_uri', redirectUri);
authUrl.searchParams.set('state', oauthState);

View File

@@ -92,16 +92,24 @@ export async function POST(request: NextRequest) {
);
}
const title = typeof json?.title === 'string' ? json.title.trim() : '';
const description = typeof json?.description === 'string' ? json.description.trim() : '';
const initBody = {
media_type: 'PHOTO',
photo_cover_index: 0,
file_paths: photoUrls,
file_extensions: photoUrls.map((url) => {
const fileName = String(new URL(url).pathname).split('/').pop() || 'photo.jpg';
const extension = fileName.split('.').pop() || 'jpg';
return extension.startsWith('.') ? extension.slice(1) : extension;
}),
post_mode: 'DIRECT_POST',
// MEDIA_UPLOAD = draft in the creator's TikTok inbox (posting
// policy is upload/draft only) and only needs the video.upload
// scope — QRMaster has no video.publish.
post_mode: 'MEDIA_UPLOAD',
post_info: {
...(title ? { title } : {}),
...(description ? { description } : {}),
},
source_info: {
source: 'PULL_FROM_URL',
photo_cover_index: 0,
photo_images: photoUrls,
},
};
const initResult = await tiktokApi(