Đính kèm nội dung đa phương tiện từ URL
curl --request POST \
--url https://app.getkavio.app/api/posts/{post}/media/from-url \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"urls": [
{}
]
}
'import requests
url = "https://app.getkavio.app/api/posts/{post}/media/from-url"
payload = { "urls": [{}] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({urls: [{}]})
};
fetch('https://app.getkavio.app/api/posts/{post}/media/from-url', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.getkavio.app/api/posts/{post}/media/from-url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'urls' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.getkavio.app/api/posts/{post}/media/from-url"
payload := strings.NewReader("{\n \"urls\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://app.getkavio.app/api/posts/{post}/media/from-url")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"urls\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.getkavio.app/api/posts/{post}/media/from-url")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"urls\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"post": {},
"attached_count": 123,
"failed_urls": [
{}
]
}Bài đăng
Đính kèm nội dung đa phương tiện từ URL
Tải ảnh hoặc video từ URL công khai rồi đính kèm vào bài đăng.
POST
/
posts
/
{post}
/
media
/
from-url
Đính kèm nội dung đa phương tiện từ URL
curl --request POST \
--url https://app.getkavio.app/api/posts/{post}/media/from-url \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"urls": [
{}
]
}
'import requests
url = "https://app.getkavio.app/api/posts/{post}/media/from-url"
payload = { "urls": [{}] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({urls: [{}]})
};
fetch('https://app.getkavio.app/api/posts/{post}/media/from-url', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.getkavio.app/api/posts/{post}/media/from-url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'urls' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.getkavio.app/api/posts/{post}/media/from-url"
payload := strings.NewReader("{\n \"urls\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://app.getkavio.app/api/posts/{post}/media/from-url")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"urls\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.getkavio.app/api/posts/{post}/media/from-url")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"urls\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"post": {},
"attached_count": 123,
"failed_urls": [
{}
]
}Để tải tệp trực tiếp từ máy thay vì lấy qua URL, hãy dùng
POST /posts/{post}/media.
Tham số đường dẫn
string
bắt buộc
UUID của bài đăng cần đính kèm nội dung đa phương tiện.
Yêu cầu
array
bắt buộc
URL HTTP/HTTPS công khai của ảnh hoặc video. Tối đa 10 URL mỗi lần gọi. Giới hạn dung lượng là 10 MB cho ảnh và 1 GB cho video.Các loại MIME hợp lệ:
- Ảnh:
image/jpeg,image/png,image/gif,image/webp - Video:
video/mp4,video/quicktime(MOV)
Cách hoạt động
- Bài đăng phải thuộc không gian làm việc hiện tại của bên gọi; nếu không, API trả về
404. - Hệ thống chỉ chấp nhận các loại nội dung đa phương tiện vừa hợp lệ, vừa được các nền tảng đang bật trong bài đăng hỗ trợ. Nếu một nền tảng không hỗ trợ loại tệp đó, tệp sẽ bị từ chối và đưa vào
failed_urls. - Tệp đính kèm thành công được thêm vào mảng
media[]của bài đăng.
Phản hồi
Trả về một đối tượng gồm ba trường:object
Bài đăng đã cập nhật, có cấu trúc giống
GET /posts/{post} , với các mục vừa đính kèm trong mảng media[].integer
Số URL đã được tải xuống và đính kèm thành công.
array
Các URL bị từ chối do không truy cập được, sai loại MIME, quá lớn hoặc không
được nền tảng đang bật nào hỗ trợ. Mỗi mục là chuỗi URL ban đầu.
curl -X POST https://app.getkavio.app/api/posts/9f1a2b3c-4d5e-6f7a-8b9c-0d1e2f3a4b5c/media/from-url \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"urls": [
"https://cdn.example.com/photo.jpg",
"https://cdn.example.com/video.mp4"
]
}'
{
"post": {
"id": "9f1a2b3c-4d5e-6f7a-8b9c-0d1e2f3a4b5c",
"content": "Launch day!",
"media": [
{
"id": "01HX1A2B3C4D5E6F7G8H9I0J1K",
"path": "medias/2681a1bf-131f-41b1-9866-755c1cb51f97.jpg",
"url": "https://media.getkavio.app/medias/2681a1bf-131f-41b1-9866-755c1cb51f97.jpg",
"type": "image",
"mime_type": "image/jpeg",
"original_filename": "photo.jpg"
}
],
"status": "draft",
"scheduled_at": null,
"published_at": null,
"platforms": [],
"labels": [],
"created_at": "2025-01-14 09:00:00",
"updated_at": "2025-01-14 09:30:00"
},
"attached_count": 1,
"failed_urls": ["https://cdn.example.com/video.mp4"]
}

