diff --git a/scripts/sync-tiktok.sh b/scripts/sync-tiktok.sh index 781a1ae..b7bd009 100644 --- a/scripts/sync-tiktok.sh +++ b/scripts/sync-tiktok.sh @@ -74,7 +74,7 @@ sync_videos() { echo "Syncing video stats..." RESPONSE=$(curl -s -X POST \ - 'https://open.tiktokapis.com/v2/video/list/?fields=id,view_count,like_count,comment_count,share_count' \ + 'https://open.tiktokapis.com/v2/video/list/?fields=id,title,view_count,like_count,comment_count,share_count' \ -H "Authorization: Bearer $ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{"max_count": 20}') @@ -84,6 +84,8 @@ sync_videos() { echo "$RESPONSE" | jq -c '.data.videos[]' | while read -r video; do VID=$(echo "$video" | jq -r '.id') + # Get first 80 chars of title, escape quotes for JSON + TITLE=$(echo "$video" | jq -r '.title // "Untitled"' | head -c 80 | sed 's/"/\\"/g') VIEWS=$(echo "$video" | jq -r '.view_count // 0') LIKES=$(echo "$video" | jq -r '.like_count // 0') COMMENTS=$(echo "$video" | jq -r '.comment_count // 0') @@ -94,7 +96,7 @@ sync_videos() { curl -s -X POST "$ARBITER_URL/sync" \ -H "Authorization: Bearer $ARBITER_TOKEN" \ -H "Content-Type: application/json" \ - -d "{\"platform\":\"tiktok\",\"platform_post_id\":\"$VID\",\"post_url\":\"$POST_URL\",\"metrics\":{\"views\":$VIEWS,\"likes\":$LIKES,\"comments\":$COMMENTS,\"shares\":$SHARES}}" > /dev/null + -d "{\"platform\":\"tiktok\",\"platform_post_id\":\"$VID\",\"post_title\":\"$TITLE\",\"post_url\":\"$POST_URL\",\"metrics\":{\"views\":$VIEWS,\"likes\":$LIKES,\"comments\":$COMMENTS,\"shares\":$SHARES}}" > /dev/null echo " $VID: $VIEWS views, $LIKES likes" done