needlaravelsite / tikapi-php
TikAPI SDK for plain PHP and Laravel โ created by NeedLaravelSite
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^9.0
- vlucas/phpdotenv: ^5.6
README
TikAPI SDK for plain PHP and Laravel, created and maintained by NeedLaravelSite.
๐ Overview
This SDK provides a clean, scalable, and framework-agnostic wrapper for the TikAPI โ making it easy to fetch TikTok data via PHP or Laravel.
โ
Works in plain PHP
โ
Fully integrated with Laravel (Service Provider + Facade)
โ
Built on Guzzle
โ
Auto-loads API keys from .env
โ
PSR-4 and PSR-12 compliant
โ
Includes feature tests for all public endpoints
๐งฐ Installation
composer require needlaravelsite/tikapi-php
Requires PHP 8.0+
โ๏ธ Laravel Setup
1. Publish Configuration
php artisan vendor:publish --provider="NeedLaravelSite\\TikApi\\TikApiServiceProvider" --tag=config
2. Add Environment Variables
TIKAPI_API_KEY=your_api_key_here TIKAPI_ACCOUNT_KEY=your_account_key_if_any TIKAPI_BASE_URL=https://api.tikapi.io
If any of these values are missing, the SDK safely defaults to environment values or fallback URLs.
๐งฑ Project Structure
src/
โโโ Client/
โ โโโ HttpClient.php
โโโ Endpoints/
โ โโโ Public/
โ โโโ Check.php
โ โโโ CommentReplies.php
โ โโโ Comments.php
โ โโโ Explore.php
โ โโโ Followers.php
โ โโโ Following.php
โ โโโ Hashtag.php
โ โโโ Likes.php
โ โโโ Music.php
โ โโโ MusicInfo.php
โ โโโ Posts.php
โ โโโ Search.php
โ โโโ Video.php
โโโ Exceptions/
โ โโโ TikApiException.php
โโโ Facades/
โ โโโ TikApi.php
โ โโโ TikApiServiceProvider.php
โโโ TikApi.php
๐งฉ Usage Examples
โ In Laravel (via Facade or DI)
Using the Facade:
use NeedLaravelSite\TikApi\Facades\TikApi; $response = TikApi::public()->explore()->list(5, 'us');
Using Dependency Injection:
use NeedLaravelSite\TikApi\TikApi; class TikApiController { public function index(TikApi $tikapi) { return $tikapi->public()->video()->get('7109178205151464746'); } }
โ In Plain PHP
<?php require 'vendor/autoload.php'; use NeedLaravelSite\TikApi\TikApi; $tikapi = new TikApi(); $response = $tikapi->public()->check()->username('lilyachty'); print_r($response);
Or provide credentials manually:
$tikapi = new TikApi('your_api_key', 'optional_account_key', 'https://api.tikapi.io');
๐ Available Endpoints
| Endpoint | Class | Description |
|---|---|---|
/public/check |
Check |
Verify TikAPI connectivity or get public user data |
/public/posts |
Posts |
Get posts by a TikTok user |
/public/likes |
Likes |
Get liked videos for a user |
/public/followers |
Followers |
Get a user's followers |
/public/following |
Following |
Get accounts followed by a user |
/public/explore |
Explore |
Get trending TikTok posts ("For You" feed) |
/public/video |
Video |
Get TikTok video details by ID |
/public/hashtag |
Hashtag |
Get posts by hashtag name or ID |
/public/comment/list |
Comments |
Get comments under a video |
/public/comment/reply/list |
CommentReplies |
Get replies to a comment |
/public/music |
Music |
Get posts using a specific sound |
/public/music/info |
MusicInfo |
Get sound metadata (title, author, duration) |
/public/search/{category} |
Search |
Search users, videos, or keywords |
๐ง Example API Calls
$tikapi = new TikApi(); // 1๏ธโฃ Get trending posts $tikapi->public()->explore()->list(10, 'us'); // 2๏ธโฃ Fetch posts by hashtag $tikapi->public()->hashtag()->list(name: 'funny', count: 10); // 3๏ธโฃ Get video info $tikapi->public()->video()->get('7109178205151464746', 'us'); // 4๏ธโฃ Get comments and replies $tikapi->public()->comments()->list('7109178205151464746'); $tikapi->public()->commentReplies()->list('7109178205151464746', '7109185042560680750'); // 5๏ธโฃ Get music information $tikapi->public()->musicInfo()->get('28459463'); // 6๏ธโฃ Perform a search $tikapi->public()->search()->general('lilyachty', 'us');
๐งช Testing
Run All Tests
vendor/bin/phpunit
Run Specific Test File
vendor/bin/phpunit tests/Feature/Public/SearchIntegrationTest.php
Run Specific Method
vendor/bin/phpunit --filter testPublicSearchGeneralReturnsSuccess
Integration tests require a valid
TIKAPI_API_KEYin your.envfile.
๐งฐ Error Handling
All errors are thrown as TikApiException for consistent handling.
use NeedLaravelSite\TikApi\Exceptions\TikApiException; try { $response = $tikapi->public()->video()->get('7109178205151464746'); } catch (TikApiException $e) { echo 'TikAPI Error: ' . $e->getMessage(); }
๐ค Contributing
Contributions are welcome under the NeedLaravelSite organization.
Guidelines
- Follow PSR-12 coding standards
- Add or update feature tests for new endpoints
- Update README when adding new functionality
๐ License
MIT License ยฉ 2025
Built by Muhammad Waqas at NeedLaravelSite