Source Crawlers
API Source Crawlers - Hướng dẫn sử dụng
Tổng quan
API Source Crawlers cung cấp các endpoint RESTful để quản lý source crawlers một cách toàn diện, bao gồm CRUD operations, quản lý status, hashtags, accounts và tìm kiếm.
Base URL và Authentication
Base URL
https://your-domain.com/apiauto/source-crawlersAuthentication
API yêu cầu xác thực thông qua Bearer token:
Authorization: Bearer YOUR_API_TOKENCác endpoint chính
1. Lấy danh sách source crawlers
Endpoint: GET /apiauto/source-crawlers
Lấy danh sách source crawlers với phân trang và bộ lọc.
Query Parameters
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
page | Integer | Không | Số trang (mặc định: 1) |
limit | Integer | Không | Số lượng crawlers mỗi trang (mặc định: 10) |
platform_type | String | Không | Lọc theo nền tảng (facebook, tiktok, youtube) |
status | String | Không | Lọc theo trạng thái (active, inactive, paused, crawled, crawling) |
source_type | String | Không | Lọc theo loại nguồn (group, page, user, post, hashtag, trending, other) |
fetch_mode | String | Không | Lọc theo chế độ lấy (once, recurring) |
search | String | Không | Tìm kiếm theo tên nguồn, URL, tác giả |
order_by | String | Không | Sắp xếp theo trường (mặc định: id) |
order_direction | String | Không | Thứ tự sắp xếp ASC/DESC (mặc định: DESC) |
Response
{
"status": "success",
"data": [
{
"id": 1,
"source_name": "Facebook Group ABC",
"source_url": "https://facebook.com/groups/abc",
"author_name": "Tác giả",
"author_url": "https://facebook.com/author",
"platform_type": "facebook",
"source_type": "group",
"crawl_interval": 60,
"status": "active",
"fetch_mode": "recurring",
"last_crawled_at": "2024-01-01 10:00:00",
"next_crawled_at": "2024-01-01 11:00:00",
"total_crawled": 100,
"created_at": "2024-01-01 10:00:00",
"updated_at": "2024-01-01 10:00:00"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 50,
"total_pages": 5,
"nextpage": "https://your-domain.com/apiauto/source-crawlers?page=2&limit=10"
}
}curl -X GET "https://your-domain.com/apiauto/source-crawlers?page=1&limit=20&status=active&platform_type=facebook" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers - Method:
GET - Query Parameters:
page: 1 limit: 20 status: active platform_type: facebook - Headers:
Authorization: Bearer YOUR_API_TOKEN
function getSourceCrawlers($token, $params = []) {
$url = 'https://your-domain.com/apiauto/source-crawlers?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$params = [
'page' => 1,
'limit' => 20,
'status' => 'active',
'platform_type' => 'facebook'
];
$result = getSourceCrawlers('YOUR_API_TOKEN', $params);import requests
def get_source_crawlers(token, params=None):
url = 'https://your-domain.com/apiauto/source-crawlers'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.get(url, params=params, headers=headers)
return response.json()
# Sử dụng
params = {
'page': 1,
'limit': 20,
'status': 'active',
'platform_type': 'facebook'
}
result = get_source_crawlers('YOUR_API_TOKEN', params)2. Lấy chi tiết một source crawler
Endpoint: GET /apiauto/source-crawlers/{id}
Lấy thông tin chi tiết của một source crawler, bao gồm info, hashtags và accounts.
Response
{
"status": "success",
"data": {
"crawler": {
"id": 1,
"source_name": "Facebook Group ABC",
"source_url": "https://facebook.com/groups/abc",
"author_name": "Tác giả",
"author_url": "https://facebook.com/author",
"platform_type": "facebook",
"source_type": "group",
"crawl_interval": 60,
"status": "active",
"fetch_mode": "recurring",
"last_crawled_at": "2024-01-01 10:00:00",
"total_crawled": 100
},
"info": {
"id": 1,
"source_description": "Mô tả nguồn",
"source_settings": "{\"key\":\"value\"}",
"crawl_filters": "{\"filter\":\"value\"}",
"crawl_keywords": "[\"keyword1\",\"keyword2\"]"
},
"hashtags": [
{
"hashtag_id": 1,
"id": 1,
"name": "#hashtag1",
"priority": 1,
"status": "active"
}
],
"accounts": [
{
"account_id": 1,
"id": 1,
"uid": "123456789",
"name": "Account Name",
"label": "Account Name (ID: 1)",
"permission": "viewer",
"status": "active"
}
]
}
}curl -X GET "https://your-domain.com/apiauto/source-crawlers/1" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1 - Method:
GET - Headers:
Authorization: Bearer YOUR_API_TOKEN
function getSourceCrawler($token, $id) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = getSourceCrawler('YOUR_API_TOKEN', 1);import requests
def get_source_crawler(token, crawler_id):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.get(url, headers=headers)
return response.json()
# Sử dụng
result = get_source_crawler('YOUR_API_TOKEN', 1)3. Tạo source crawler mới
Endpoint: POST /apiauto/source-crawlers
Tạo một source crawler mới.
Request Body
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
source_name | String | Không | Tên nguồn (tự động tạo nếu trống) |
source_url | String | Không | URL nguồn (phải là URL hợp lệ) |
author_name | String | Không | Tên tác giả |
author_url | String | Không | URL tác giả (phải là URL hợp lệ) |
platform_type | String | Có | Nền tảng (facebook, tiktok, youtube) |
source_type | String | Có | Loại nguồn (group, page, user, post, hashtag, trending, other) |
crawl_interval | Integer | Có | Thời gian crawl (phút). Nếu fetch_mode=once thì = 0, nếu recurring thì >= 5 |
status | String | Không | Trạng thái (mặc định: paused) |
fetch_mode | String | Không | Chế độ lấy (once, recurring, mặc định: once) |
source_description | String | Không | Mô tả nguồn |
source_settings | Object/String | Không | Cài đặt crawler (JSON object hoặc JSON string) |
crawl_filters | Object/String | Không | Bộ lọc crawler (JSON object hoặc JSON string) |
crawl_keywords | Array/String | Không | Từ khóa crawler (array hoặc comma-separated string) |
Request Example
{
"source_name": "Facebook Group ABC",
"source_url": "https://facebook.com/groups/abc",
"platform_type": "facebook",
"source_type": "group",
"crawl_interval": 60,
"fetch_mode": "recurring",
"status": "paused",
"source_description": "Mô tả nguồn",
"source_settings": {
"key": "value"
},
"crawl_keywords": ["keyword1", "keyword2"]
}Response
{
"status": "success",
"message": "Tạo crawler thành công",
"data": {
"id": 1,
"source_name": "Facebook Group ABC",
...
}
}Lưu ý:
- Nếu
status = 'active'nhưng chưa có account liên kết, crawler sẽ tự động chuyển vềpaused - Nếu
fetch_mode = 'once',crawl_intervalsẽ tự động được set = 0 - Nếu
fetch_mode = 'recurring',crawl_intervalphải >= 5 phút - Nếu
source_nametrống, sẽ tự động tạo từauthor_namehoặc domain củasource_url
curl -X POST "https://your-domain.com/apiauto/source-crawlers" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"source_name": "Facebook Group ABC",
"platform_type": "facebook",
"source_type": "group",
"crawl_interval": 60,
"fetch_mode": "recurring"
}'Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers - Method:
POST - Send Body:
true - Body Type:
JSON - Headers:
Authorization: Bearer YOUR_API_TOKEN Content-Type: application/json - Body (JSON):
{ "source_name": "Facebook Group ABC", "platform_type": "facebook", "source_type": "group", "crawl_interval": 60, "fetch_mode": "recurring", "source_description": "Mô tả nguồn", "crawl_keywords": ["keyword1", "keyword2"] }
function createSourceCrawler($token, $data) {
$url = 'https://your-domain.com/apiauto/source-crawlers';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$data = [
'source_name' => 'Facebook Group ABC',
'platform_type' => 'facebook',
'source_type' => 'group',
'crawl_interval' => 60,
'fetch_mode' => 'recurring',
'crawl_keywords' => ['keyword1', 'keyword2']
];
$result = createSourceCrawler('YOUR_API_TOKEN', $data);import requests
import json
def create_source_crawler(token, data):
url = 'https://your-domain.com/apiauto/source-crawlers'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
# Sử dụng
data = {
'source_name': 'Facebook Group ABC',
'platform_type': 'facebook',
'source_type': 'group',
'crawl_interval': 60,
'fetch_mode': 'recurring',
'crawl_keywords': ['keyword1', 'keyword2']
}
result = create_source_crawler('YOUR_API_TOKEN', data)4. Cập nhật source crawler
Endpoint: PUT /apiauto/source-crawlers/{id}
Cập nhật thông tin của một source crawler.
Request Body
Tương tự như tạo crawler, nhưng tất cả các trường đều không bắt buộc (chỉ cập nhật các trường được gửi lên).
Response
{
"status": "success",
"message": "Cập nhật crawler thành công",
"data": {
"id": 1,
"source_name": "Facebook Group ABC Updated",
...
}
}curl -X PUT "https://your-domain.com/apiauto/source-crawlers/1" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"source_name": "Facebook Group ABC Updated",
"status": "active"
}'Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1 - Method:
PUT - Send Body:
true - Body Type:
JSON - Headers:
Authorization: Bearer YOUR_API_TOKEN Content-Type: application/json - Body (JSON):
{ "source_name": "Facebook Group ABC Updated", "status": "active" }
function updateSourceCrawler($token, $id, $data) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$data = [
'source_name' => 'Facebook Group ABC Updated',
'status' => 'active'
];
$result = updateSourceCrawler('YOUR_API_TOKEN', 1, $data);import requests
import json
def update_source_crawler(token, crawler_id, data):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
response = requests.put(url, headers=headers, data=json.dumps(data))
return response.json()
# Sử dụng
data = {
'source_name': 'Facebook Group ABC Updated',
'status': 'active'
}
result = update_source_crawler('YOUR_API_TOKEN', 1, data)5. Xóa source crawler
Endpoint: DELETE /apiauto/source-crawlers/{id}
Xóa một source crawler (bao gồm cascade delete: info, hashtags, accounts).
Response
{
"status": "success",
"message": "Xóa crawler thành công"
}curl -X DELETE "https://your-domain.com/apiauto/source-crawlers/1" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1 - Method:
DELETE - Headers:
Authorization: Bearer YOUR_API_TOKEN
function deleteSourceCrawler($token, $id) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = deleteSourceCrawler('YOUR_API_TOKEN', 1);import requests
def delete_source_crawler(token, crawler_id):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.delete(url, headers=headers)
return response.json()
# Sử dụng
result = delete_source_crawler('YOUR_API_TOKEN', 1)6. Tạm dừng crawler
Endpoint: PATCH /apiauto/source-crawlers/{id}/pause
Tạm dừng một crawler (chuyển status về paused).
Response
{
"status": "success",
"message": "Tạm dừng crawler thành công",
"data": {
"id": 1,
"status": "paused",
...
}
}curl -X PATCH "https://your-domain.com/apiauto/source-crawlers/1/pause" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/pause - Method:
PATCH - Headers:
Authorization: Bearer YOUR_API_TOKEN
function pauseSourceCrawler($token, $id) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/pause";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = pauseSourceCrawler('YOUR_API_TOKEN', 1);import requests
def pause_source_crawler(token, crawler_id):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/pause'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.patch(url, headers=headers)
return response.json()
# Sử dụng
result = pause_source_crawler('YOUR_API_TOKEN', 1)7. Tiếp tục crawler
Endpoint: PATCH /apiauto/source-crawlers/{id}/resume
Kích hoạt một crawler (chuyển status về active). Yêu cầu crawler phải có ít nhất một account liên kết.
Response
{
"status": "success",
"message": "Kích hoạt crawler thành công",
"data": {
"id": 1,
"status": "active",
...
}
}Lưu ý: Nếu crawler chưa có account liên kết, sẽ trả về lỗi NO_ACCOUNTS.
curl -X PATCH "https://your-domain.com/apiauto/source-crawlers/1/resume" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/resume - Method:
PATCH - Headers:
Authorization: Bearer YOUR_API_TOKEN
function resumeSourceCrawler($token, $id) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/resume";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = resumeSourceCrawler('YOUR_API_TOKEN', 1);import requests
def resume_source_crawler(token, crawler_id):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/resume'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.patch(url, headers=headers)
return response.json()
# Sử dụng
result = resume_source_crawler('YOUR_API_TOKEN', 1)Quản lý Hashtags
8. Lấy hashtags của crawler
Endpoint: GET /apiauto/source-crawlers/{id}/hashtags
Lấy danh sách hashtags đã liên kết với crawler.
Response
{
"status": "success",
"data": [
{
"id": 1,
"hashtag_id": 5,
"name": "#hashtag1",
"priority": 1,
"status": "active"
}
]
}curl -X GET "https://your-domain.com/apiauto/source-crawlers/1/hashtags" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/hashtags - Method:
GET - Headers:
Authorization: Bearer YOUR_API_TOKEN
function getCrawlerHashtags($token, $id) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/hashtags";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = getCrawlerHashtags('YOUR_API_TOKEN', 1);import requests
def get_crawler_hashtags(token, crawler_id):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/hashtags'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.get(url, headers=headers)
return response.json()
# Sử dụng
result = get_crawler_hashtags('YOUR_API_TOKEN', 1)9. Thêm hashtag cho crawler
Endpoint: POST /apiauto/source-crawlers/{id}/hashtags
Thêm một hashtag vào crawler.
Request Body
{
"hashtag_id": 5,
"priority": 1,
"status": "active"
}| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
hashtag_id | Integer | Có | ID của hashtag |
priority | Integer | Không | Độ ưu tiên (1-10, mặc định: 1) |
status | String | Không | Trạng thái (active, inactive, mặc định: active) |
Response
{
"status": "success",
"message": "Thêm hashtag thành công"
}curl -X POST "https://your-domain.com/apiauto/source-crawlers/1/hashtags" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"hashtag_id": 5,
"priority": 1
}'Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/hashtags - Method:
POST - Send Body:
true - Body Type:
JSON - Headers:
Authorization: Bearer YOUR_API_TOKEN Content-Type: application/json - Body (JSON):
{ "hashtag_id": 5, "priority": 1, "status": "active" }
function addCrawlerHashtag($token, $id, $data) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/hashtags";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$data = [
'hashtag_id' => 5,
'priority' => 1
];
$result = addCrawlerHashtag('YOUR_API_TOKEN', 1, $data);import requests
import json
def add_crawler_hashtag(token, crawler_id, data):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/hashtags'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
# Sử dụng
data = {
'hashtag_id': 5,
'priority': 1
}
result = add_crawler_hashtag('YOUR_API_TOKEN', 1, data)10. Xóa hashtag khỏi crawler
Endpoint: DELETE /apiauto/source-crawlers/{id}/hashtags/{hashtagId}
Xóa một hashtag khỏi crawler.
Response
{
"status": "success",
"message": "Xóa hashtag thành công"
}curl -X DELETE "https://your-domain.com/apiauto/source-crawlers/1/hashtags/5" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/hashtags/5 - Method:
DELETE - Headers:
Authorization: Bearer YOUR_API_TOKEN
function removeCrawlerHashtag($token, $id, $hashtagId) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/hashtags/{$hashtagId}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = removeCrawlerHashtag('YOUR_API_TOKEN', 1, 5);import requests
def remove_crawler_hashtag(token, crawler_id, hashtag_id):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/hashtags/{hashtag_id}'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.delete(url, headers=headers)
return response.json()
# Sử dụng
result = remove_crawler_hashtag('YOUR_API_TOKEN', 1, 5)11. Cập nhật priority của hashtag
Endpoint: PATCH /apiauto/source-crawlers/{id}/hashtags/{hashtagId}/priority
Cập nhật độ ưu tiên của hashtag.
Request Body
{
"priority": 5
}| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
priority | Integer | Có | Độ ưu tiên (1-10) |
Response
{
"status": "success",
"message": "Cập nhật priority thành công"
}curl -X PATCH "https://your-domain.com/apiauto/source-crawlers/1/hashtags/5/priority" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"priority": 5
}'Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/hashtags/5/priority - Method:
PATCH - Send Body:
true - Body Type:
JSON - Headers:
Authorization: Bearer YOUR_API_TOKEN Content-Type: application/json - Body (JSON):
{ "priority": 5 }
function updateHashtagPriority($token, $id, $hashtagId, $priority) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/hashtags/{$hashtagId}/priority";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['priority' => $priority]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = updateHashtagPriority('YOUR_API_TOKEN', 1, 5, 5);import requests
import json
def update_hashtag_priority(token, crawler_id, hashtag_id, priority):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/hashtags/{hashtag_id}/priority'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
data = {'priority': priority}
response = requests.patch(url, headers=headers, data=json.dumps(data))
return response.json()
# Sử dụng
result = update_hashtag_priority('YOUR_API_TOKEN', 1, 5, 5)Quản lý Accounts
12. Lấy accounts của crawler
Endpoint: GET /apiauto/source-crawlers/{id}/accounts
Lấy danh sách accounts đã liên kết với crawler.
Response
{
"status": "success",
"data": [
{
"id": 1,
"account_id": 10,
"uid": "123456789",
"name": "Account Name",
"label": "Account Name (ID: 10)",
"permission": "viewer",
"status": "active"
}
]
}curl -X GET "https://your-domain.com/apiauto/source-crawlers/1/accounts" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/accounts - Method:
GET - Headers:
Authorization: Bearer YOUR_API_TOKEN
function getCrawlerAccounts($token, $id) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/accounts";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = getCrawlerAccounts('YOUR_API_TOKEN', 1);import requests
def get_crawler_accounts(token, crawler_id):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/accounts'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.get(url, headers=headers)
return response.json()
# Sử dụng
result = get_crawler_accounts('YOUR_API_TOKEN', 1)13. Thêm account cho crawler
Endpoint: POST /apiauto/source-crawlers/{id}/accounts
Thêm một account vào crawler.
Request Body
{
"account_id": 10,
"permission": "viewer",
"status": "active"
}| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
account_id | Integer | Có | ID của Facebook account |
permission | String | Không | Quyền (admin, editor, viewer, mặc định: viewer) |
status | String | Không | Trạng thái (active, inactive, mặc định: active) |
Response
{
"status": "success",
"message": "Thêm account thành công"
}Lưu ý: Nếu account đã được liên kết, sẽ trả về lỗi DUPLICATE_ACCOUNT.
curl -X POST "https://your-domain.com/apiauto/source-crawlers/1/accounts" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"account_id": 10,
"permission": "viewer"
}'Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/accounts - Method:
POST - Send Body:
true - Body Type:
JSON - Headers:
Authorization: Bearer YOUR_API_TOKEN Content-Type: application/json - Body (JSON):
{ "account_id": 10, "permission": "viewer", "status": "active" }
function addCrawlerAccount($token, $id, $data) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/accounts";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$data = [
'account_id' => 10,
'permission' => 'viewer'
];
$result = addCrawlerAccount('YOUR_API_TOKEN', 1, $data);import requests
import json
def add_crawler_account(token, crawler_id, data):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/accounts'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
# Sử dụng
data = {
'account_id': 10,
'permission': 'viewer'
}
result = add_crawler_account('YOUR_API_TOKEN', 1, data)14. Thêm nhiều accounts cho crawler
Endpoint: POST /apiauto/source-crawlers/{id}/accounts/bulk
Thêm nhiều accounts vào crawler cùng lúc.
Request Body
{
"account_ids": [10, 11, 12],
"permission": "viewer",
"status": "active"
}| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
account_ids | Array | Có | Mảng các ID của Facebook accounts |
permission | String | Không | Quyền áp dụng cho tất cả accounts (mặc định: viewer) |
status | String | Không | Trạng thái áp dụng cho tất cả accounts (mặc định: active) |
Response
{
"status": "success",
"message": "Đã thêm 3 account(s)",
"data": {
"success_count": 3,
"total": 3
}
}curl -X POST "https://your-domain.com/apiauto/source-crawlers/1/accounts/bulk" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"account_ids": [10, 11, 12],
"permission": "viewer"
}'Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/accounts/bulk - Method:
POST - Send Body:
true - Body Type:
JSON - Headers:
Authorization: Bearer YOUR_API_TOKEN Content-Type: application/json - Body (JSON):
{ "account_ids": [10, 11, 12], "permission": "viewer", "status": "active" }
function addCrawlerAccounts($token, $id, $data) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/accounts/bulk";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$data = [
'account_ids' => [10, 11, 12],
'permission' => 'viewer'
];
$result = addCrawlerAccounts('YOUR_API_TOKEN', 1, $data);import requests
import json
def add_crawler_accounts(token, crawler_id, data):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/accounts/bulk'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
# Sử dụng
data = {
'account_ids': [10, 11, 12],
'permission': 'viewer'
}
result = add_crawler_accounts('YOUR_API_TOKEN', 1, data)15. Xóa account khỏi crawler
Endpoint: DELETE /apiauto/source-crawlers/{id}/accounts/{accountId}
Xóa một account khỏi crawler.
Response
{
"status": "success",
"message": "Xóa account thành công"
}Lưu ý: Nếu xóa account cuối cùng và crawler đang ở trạng thái active, crawler sẽ tự động chuyển về paused.
curl -X DELETE "https://your-domain.com/apiauto/source-crawlers/1/accounts/10" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/1/accounts/10 - Method:
DELETE - Headers:
Authorization: Bearer YOUR_API_TOKEN
function removeCrawlerAccount($token, $id, $accountId) {
$url = "https://your-domain.com/apiauto/source-crawlers/{$id}/accounts/{$accountId}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = removeCrawlerAccount('YOUR_API_TOKEN', 1, 10);import requests
def remove_crawler_account(token, crawler_id, account_id):
url = f'https://your-domain.com/apiauto/source-crawlers/{crawler_id}/accounts/{account_id}'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.delete(url, headers=headers)
return response.json()
# Sử dụng
result = remove_crawler_account('YOUR_API_TOKEN', 1, 10)Tìm kiếm
16. Tìm kiếm hashtags
Endpoint: GET /apiauto/source-crawlers/search/hashtags
Tìm kiếm hashtags để liên kết với crawler.
Query Parameters
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
q | String | Không | Từ khóa tìm kiếm |
Response
{
"status": "success",
"results": [
{
"id": 1,
"text": "#hashtag1"
},
{
"id": 2,
"text": "#hashtag2"
}
]
}curl -X GET "https://your-domain.com/apiauto/source-crawlers/search/hashtags?q=hashtag" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/search/hashtags - Method:
GET - Query Parameters:
q: hashtag - Headers:
Authorization: Bearer YOUR_API_TOKEN
function searchHashtags($token, $query = '') {
$url = 'https://your-domain.com/apiauto/source-crawlers/search/hashtags';
if ($query) {
$url .= '?q=' . urlencode($query);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = searchHashtags('YOUR_API_TOKEN', 'hashtag');import requests
def search_hashtags(token, query=''):
url = 'https://your-domain.com/apiauto/source-crawlers/search/hashtags'
headers = {
'Authorization': f'Bearer {token}'
}
params = {}
if query:
params['q'] = query
response = requests.get(url, params=params, headers=headers)
return response.json()
# Sử dụng
result = search_hashtags('YOUR_API_TOKEN', 'hashtag')17. Tìm kiếm accounts
Endpoint: GET /apiauto/source-crawlers/search/accounts
Tìm kiếm Facebook accounts để liên kết với crawler.
Query Parameters
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
q | String | Không | Từ khóa tìm kiếm (tên, ID, gpmlocal_id) |
Response
{
"status": "success",
"results": [
{
"id": 10,
"uid": "123456789",
"status": "live",
"text": "Account Name (ID: 10, UID: 123456789, Status: live)"
}
]
}Lưu ý: Chỉ trả về các accounts có u_active = 1 và u_status trong ['live', 'detect', 'login'].
curl -X GET "https://your-domain.com/apiauto/source-crawlers/search/accounts?q=account" \
-H "Authorization: Bearer YOUR_API_TOKEN"Cấu hình HTTP Request Node:
- URL:
https://your-domain.com/apiauto/source-crawlers/search/accounts - Method:
GET - Query Parameters:
q: account - Headers:
Authorization: Bearer YOUR_API_TOKEN
function searchAccounts($token, $query = '') {
$url = 'https://your-domain.com/apiauto/source-crawlers/search/accounts';
if ($query) {
$url .= '?q=' . urlencode($query);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = searchAccounts('YOUR_API_TOKEN', 'account');import requests
def search_accounts(token, query=''):
url = 'https://your-domain.com/apiauto/source-crawlers/search/accounts'
headers = {
'Authorization': f'Bearer {token}'
}
params = {}
if query:
params['q'] = query
response = requests.get(url, params=params, headers=headers)
return response.json()
# Sử dụng
result = search_accounts('YOUR_API_TOKEN', 'account')Error Responses
API trả về các mã lỗi chuẩn HTTP và format lỗi thống nhất:
Format lỗi
{
"status": "error",
"code": "ERROR_CODE",
"message": "Mô tả lỗi chi tiết"
}Các mã lỗi thường gặp
| HTTP Status | Code | Mô tả |
|---|---|---|
| 400 | VALIDATION_ERROR | Dữ liệu không hợp lệ |
| 400 | MISSING_ID | Thiếu ID crawler |
| 400 | INVALID_INTERVAL | Interval không hợp lệ (recurring phải >= 5 phút) |
| 400 | NO_ACCOUNTS | Chưa có account liên kết (khi resume) |
| 400 | DUPLICATE_ACCOUNT | Account đã được liên kết |
| 400 | INVALID_PRIORITY | Priority không hợp lệ (phải từ 1-10) |
| 404 | NOT_FOUND | Không tìm thấy crawler/hashtag/account |
| 500 | SYSTEM_ERROR | Lỗi hệ thống |
Ví dụ lỗi
{
"status": "error",
"code": "NO_ACCOUNTS",
"message": "Không thể kích hoạt vì chưa có tài khoản liên kết"
}Best Practices
- Status Management: Luôn kiểm tra có account liên kết trước khi activate crawler
- Fetch Mode:
- Sử dụng
oncecho crawl một lần - Sử dụng
recurringvớicrawl_interval >= 5cho crawl định kỳ
- Sử dụng
- Cascade Delete: Khi xóa crawler, tất cả dữ liệu liên quan (info, hashtags, accounts) sẽ bị xóa
- Auto Pause: Crawler sẽ tự động chuyển về
pausednếu không có account khi activate - Keywords Format: Có thể gửi
crawl_keywordsdưới dạng array hoặc comma-separated string
Notes
- Tất cả các endpoint đều yêu cầu authentication
source_settingsvàcrawl_filterscó thể gửi dưới dạng JSON object hoặc JSON stringcrawl_keywordscó thể gửi dưới dạng array hoặc comma-separated string (ví dụ: "keyword1, keyword2")- Khi xóa account cuối cùng, crawler sẽ tự động chuyển về
pausednếu đangactive - Không thể resume crawler nếu chưa có account liên kết
- Priority của hashtag phải từ 1 đến 10
