ssovit / tiktok-private-api
PHP的不官方TikTok私有API
1.0.7
2022-08-10 09:55 UTC
Requires
- guzzlehttp/guzzle: ^6.5 || ^7.0
README
私有API访问的API包装器
安装
通过composer composer require ssovit/tiktok-private-api
这是如何工作的?
为了使此功能正常工作,需要订阅我的私有API服务器。详情见下文。
文档
https://ssovit.github.io/TikTok-Private-API-PHP/
使用方法
请遵循 /example
目录中的示例
$api=new \Sovit\TikTokPrivate\Api(array(/* config array*/)); $trendingFeed=$api->getForYou($maxCursor=0); $userData=$api->getUser("USERNAME"); $userFeed=$api->getUserFeed("USER_ID",$maxCursor=0); $challenge=$api->getChallenge("CHALLENGE_ID"); $challengeFeed=$api->getChallengeFeed("CHALLENGE_ID",$maxCursor=0); $musc=$api->getMusic("6798898508385585925"); $musicFeed=$api->getMusicFeed("6798898508385585925",$maxCursor=0); $videoData=$api->getVideoByID("6829540826570296577"); $videoData=$api->getVideoByUrl("https://www.tiktok.com/@zachking/video/6829303572832750853"); // More to come
可用选项
$api=new \Sovit\TikTokPrivate\Api(array( "proxy" => '', // proxy in url format like http://username:password@host:port "cache_timeout" => 3600 // 1 hours cache timeout "transform_result" => true, // false if you want to get json without transforming it to more readable JSON structure "api_key" => "API_KEY" // see below on how to get API key ), $cache_engine=false);
缓存引擎
您可以根据自己的需求构建一个引擎,用于存储和检索本地存储中的缓存,以避免频繁请求TikTok服务器。这有助于防止因频繁请求而被TikTok服务器封禁。
缓存引擎应具有API类使用的可调用 get
和 set
方法
// Example using WordPress transient as cache engine Class MyCacheEngine{ function get($cache_key){ return get_transient($cache_key); } function set($cache_key,$data,$timeout=3600){ return set_transient($cache_key,$data,$timeout); } }
使用方法
$cache_engine=new MyCacheEngine(); $api=new \Sovit\TikTokPrivate\Api(array(/* config array*/),$cache_engine);
可用方法
getForYou
- 获取热门推荐getForYou($maxCursor)
getUser
- 获取TikTok用户的资料getUser($username)
getUserFeed
- 通过ID获取用户动态getUserFeed($user_id,$maxCursor)
getChallenge
- 获取挑战/标签信息getChallenge($challenge)
getChallengeFeed
- 通过ID获取挑战动态getChallengeFeed($challenge_id, $maxCursor)
getMusic
- 获取音乐信息getMusic($music_id)
getMusicFeed
- 获取音乐动态getMusicFeed($music_id,$maxCursor)
getVideoByID
- 通过ID获取视频getVideoByID($video_id)
getVideoByUrl
- 通过URL获取视频getVideoByUrl($video_url)
- 并非所有方法都有文档,将在我有空时更新
$maxCursor
默认为0
,用于结果页面的偏移。下一页的maxCursor
在当前页面的调用中暴露。
私有API服务器订阅定价
不再可用