API Documentation
SocialStatsAPI provides endpoints to track and analyze social media posts. Below are detailed instructions on using the API.
1. Authentication
All API requests must include the HTTP header K
with a valid secret key. You can find your secret key on your personal account page.
2. Add URLs to Tracking
Endpoint:
POST https://socialstatsapi.com/api/track
Request Parameters (Form Data):
url
(string, required) - The social post URL to track.tags
(array, optional) - Tags for categorization and search.uid
(string, optional) - User-defined identifier for tracking.
Response:
{ "ok": true } or { "error": "Failure reason" }
Examples:
Bash (cURL)
curl -H "K: your-secret-key" -X POST https://socialstatsapi.com/api/track \
-d "urls[0][url]=https://twitter.com/post123&urls[0][tags][]=news&urls[0][uid]=post-001"
PHP
$data = [
'urls[0][url]' => 'https://twitter.com/post123',
'urls[0][tags][]' => 'news',
'urls[0][uid]' => 'post-001'
];
$options = [
'http' => [
'header' => "K: your-secret-key\r\nContent-Type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents('https://socialstatsapi.com/api/track', false, $context);
Python
import requests
headers = {"K": "your-secret-key"}
data = {
"urls[0][url]": "https://twitter.com/post123",
"urls[0][tags][]": "news",
"urls[0][uid]": "post-001"
}
response = requests.post("https://socialstatsapi.com/api/track", headers=headers, data=data)
print(response.json())
Node.js
const axios = require('axios');
axios.post('https://socialstatsapi.com/api/track', new URLSearchParams({
'urls[0][url]': 'https://twitter.com/post123',
'urls[0][tags][]': 'news',
'urls[0][uid]': 'post-001'
}), {
headers: { 'K': 'your-secret-key' }
}).then(response => console.log(response.data));
3. Retrieve URL Statistics
Endpoint:
POST https://socialstatsapi.com/api/stats
Request Parameters (Form Data):
uid
(string, required) - The UID of the tracked URL.
Response Format (CSV by Default):
uid, url, views, likes, comments, last_ts
- uid - User-defined identifier.
- url - The monitored social media post URL.
- views - Number of views the post has received.
- likes - Number of likes.
- comments - Number of comments.
- last_ts - Timestamp of the last update.
Examples:
Bash (cURL)
curl -H "K: your-secret-key" -X POST https://socialstatsapi.com/api/stats \
-d "urls[0][uid]=post-001"
PHP
$data = ['urls[0][uid]' => 'post-001'];
$options = [
'http' => [
'header' => "K: your-secret-key\r\nContent-Type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents('https://socialstatsapi.com/api/stats', false, $context);
echo $result;
Python
response = requests.post("https://socialstatsapi.com/api/stats", headers=headers, data={"urls[0][uid]": "post-001"})
print(response.text)
Node.js
axios.post('https://socialstatsapi.com/api/stats', new URLSearchParams({
'urls[0][uid]': 'post-001'
}), {
headers: { 'K': 'your-secret-key' }
}).then(response => console.log(response.data));