728x90
반응형
파이썬을 이용해서 틱톡에 동영상을 업로드하는 함수를 만들어봤다.
API를 사용하는 방법이고 입력 값이 토큰은 이전에 업로드된 함수를 이용해 받아야한다.
video_url은 https 로 만들어진 동영상 주소를 입력하면 된다.
def uploadVod(access_token, video_url, title):
api_url = "https://open.tiktokapis.com/v2/post/publish/video/init/"
# 요청 본문 데이터
body = {
"post_info": {
"title": title,
"privacy_level": "SELF_ONLY",
"disable_duet": False,
"disable_comment": True,
"disable_stitch": False,
"video_cover_timestamp_ms": 1000
},
"source_info": {
"source": "PULL_FROM_URL",
"video_url": video_url,
}
}
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json; charset=UTF-8"
}
try:
response = requests.post(api_url, headers=headers, json=body)
result = response.json()
if response.status_code == 200 and result['error']['code'] == "ok":
publish_id = result['data']['publish_id']
print(f"업로드 성공 = {publish_id}")
return {"rst": "1","value": publish_id}
else:
print("업로드 실패")
return {"rst": "0", "value": result}
except Exception as e:
print(f"요청 중 오류 발생: {str(e)}")
return {"rst": "0", "value": e}

728x90
반응형
'파이썬' 카테고리의 다른 글
| 파이썬에서 로그파일 쌓기 (0) | 2026.01.19 |
|---|---|
| 파이썬 mysql 처리 클래스 (0) | 2026.01.19 |
| 날짜처리하는 방법 리스트 (0) | 2026.01.15 |
| 틱톡 토큰 갱신하기 (0) | 2026.01.14 |
| 틱톡 토큰 발급받기 (0) | 2026.01.14 |