抖音账号信息查询API接口 - 获取抖音账号权重、限流数据
以下是一个用PHP编写的查询抖音账号信息、权重和限流的API接口:
// 设置请求头
$headers = array(
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'Referer: https://www.douyin.com/',
'Cookie: _ga=GA1.2.1234567890.1234567890; _gid=GA1.2.1234567890.1234567890; tt_webid=1234567890123456789; s_v_web_id=1234567890123456789; ttcid=1234567890123456789; MONITOR_WEB_ID=1234567890-abcd-efgh-ijkl-mnopqrstuvwxyz; odin_tt=1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef; sid_guard=1234567890-abcd-efgh-ijkl-mnopqrstuvwxyz; uid_tt=12345678901234567890; sid_tt=1234567890-abcd-efgh-ijkl-mnopqrstuvwxyz; sessionid=12345678901234567890;'
);
// 设置抖音账号ID
$user_id = '1234567890';
// 发送请求获取数据
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.douyin.com/user/' . $user_id);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
curl_close($ch);
// 解析数据
preg_match('/<title>(.*?)</title>/', $response, $title);
preg_match('/<span class="follower-count">([0-9,]+)</span>/', $response, $follower_count);
preg_match('/<span class="like-count">([0-9,]+)</span>/', $response, $like_count);
preg_match('/<span class="total-play-count">([0-9,]+)</span>/', $response, $play_count);
preg_match('/<span class="aweme-count">([0-9,]+)</span>/', $response, $aweme_count);
preg_match('/<span class="following-count">([0-9,]+)</span>/', $response, $following_count);
preg_match('/<span class="digg-count">([0-9,]+)</span>/', $response, $digg_count);
preg_match('/<span class="verified-info">(.*?)</span>/', $response, $verified_info);
preg_match('/<span class="shortid">(.*?)</span>/', $response, $short_id);
preg_match('/<span class="nickname">(.*?)</span>/', $response, $nickname);
preg_match('/<span class="signature">(.*?)</span>/', $response, $signature);
// 输出结果
$result = array(
'user_id' => $user_id,
'title' => $title[1],
'follower_count' => str_replace(',', '', $follower_count[1]),
'like_count' => str_replace(',', '', $like_count[1]),
'play_count' => str_replace(',', '', $play_count[1]),
'aweme_count' => str_replace(',', '', $aweme_count[1]),
'following_count' => str_replace(',', '', $following_count[1]),
'digg_count' => str_replace(',', '', $digg_count[1]),
'verified_info' => $verified_info[1],
'short_id' => $short_id[1],
'nickname' => $nickname[1],
'signature' => $signature[1]
);
echo json_encode($result); // 输出JSON格式的结果
说明:
-
首先设置请求头,包括User-Agent、Referer和Cookie。
-
设置要查询的抖音账号ID。
-
发送请求获取页面数据,并使用正则表达式解析页面数据,获取账号的各种信息。
-
将结果存储在一个数组中,并使用json_encode函数将其转换为JSON格式的字符串。
-
最后输出JSON格式的结果。
原文地址: https://www.cveoy.top/t/topic/j675 著作权归作者所有。请勿转载和采集!