틱톡API를 이용해서 동영상을 업로드하는 함수를 만들어봤다.
영상 업로드 방식은 서버에 있는 영상을 업로드하는 방식과
URL이 있는 영상을 업로드하는 방식이 있는데 아래 함수는 두번 째 방법인
URL을 이용한 방법이다.
결과 값으로 ID 값을 리턴해주는데 이 아이디 값은 임시 값이 서비스 ID 값은
처리가 완료되면 이 임시 값을 이용해 조회할 수 있다.
또한, privacy_level 은 sand box 환경에서 테스트하기 위해 SELF_ONLY를 사용했다
function uploadVod($accessToken, $title, $vodURL){
$url = 'https://open.tiktokapis.com/v2/post/publish/video/init/';
$data = [
'post_info' => [
'title' => $title,
'privacy_level' => 'SELF_ONLY', //PUBLIC_TO_EVERYONE
'disable_duet' => false,
'disable_comment' => true,
'disable_stitch' => false,
'video_cover_timestamp_ms' => 1000
],
'source_info' => [
'source' => 'PULL_FROM_URL',
'video_url' => $vodURL
]
];
$jsonData = json_encode($data);
$headers = [
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json; charset=UTF-8',
'Content-Length: ' . strlen($jsonData)
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if (curl_errno($ch) || $responseData['error']['code']!="ok") {
echo 'cURL Error: ' . curl_error($ch);
echo "error msg=" . $responseData['error']['message'];
} else {
return $responseData['data']['publish_id'];
}
}

'기타' 카테고리의 다른 글
| TR 에 마우스 오버 시 색 변경하기 (0) | 2025.12.31 |
|---|---|
| 틱톡 API로 동영상 업로드하기 6 : 비디오 아이디 가져오기 (PHP) (0) | 2025.12.29 |
| 틱톡 API로 동영상 업로드하기 4 : 토큰 (PHP) (0) | 2025.12.26 |
| 틱톡 API로 동영상 업로드하기 3 : Authorize Code (PHP) (1) | 2025.12.26 |
| 틱톡 API로 동영상 업로드하기 2 : Sandbox (0) | 2025.12.23 |