liballab/tiktok-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

liballab/tiktok-php

Composer 安装命令:

composer require liballab/tiktok-php

包简介

TikTok Scraper in PHP

README 文档

README

By default, this scraper will attempt to use NodeJS to sign the URL. If you do not have node installed, it will attempt to install it during the composer install step. If you do, it will simply find the path to it. If you'd like to change this logic, you can read more below about setting your signMethod => 'datafetch', an API I have created for signing tiktok urls.

1.9.14

Updates to the user->account method have been made. No changes in the response object.

1.9.13

Introducing $scraper->user->videoFromEmbed('id');

This will return video data from the embed endpoint. Right now it's more stable than the normal video route. The only catch is that it does not return

1.9.12

Setting verifyFp manually is now an option, as captcha verification has been taking TikTok by storm. You can set it like so:

$scraper = new Scraper([
  'verifyFp' => 'verify_xxxxx_xxxx_xxxx_xxx...'
])

If you do not set one, by default, the scraper will attempt to generate the following cookies for you:

verifyFp, tt_webid, and tt_webid_v2

However, in most cases at this moment, the fp token will end up being a trigger for captcha.

Cookie File

In v1.8.0, the scraper now sets cookies by default, which means that you must provide writable permissions for a cookies.json file, and then set it in the configuration (see example config below).

Need to disable cookies? Set 'disableCookies' => true in the configuration.

Installation

composer require robert-grubb/tiktok-php

Instantiation

require './vendor/autoload.php';

use TikTok\Scraper;

// Instantiate TikTok Scraper library
$scraper = new Scraper([
  // Sign method
  'signMethod' => 'datafetch'
  'datafetchApiKey' => ''
  'userAgent' => '',
  'proxy' => [
    'protocol' => 'http',
    'address' => '127.0.0.1:8080',
    'auth' => 'username:password'
  ],
  'timeout' => 20,

  // Since v1.8.0 (Must set cookie file)
  'cookieFile' => __DIR__ . '/cookies.json'

  // If not using cookies:
  'disableCookies' => true
]);

Configuration Explained

[
  // Sign method
  'signMethod' => 'node' // Or datafetch

  // User agent
  'userAgent' => '',

  // Optional proxy (auth is also optional)
  'proxy' => [
    'protocol' => 'http',
    'address' => '127.0.0.1:8080',
    'auth' => 'username:password'
  ],

  // Time before curl request times out
  'timeout' => 20
]

Search for a user

// 30 being the number of results
$scraper->user->search('username', 30);

User data

$scraper->user->details('username');

User videos

$scraper->user->videos(123415125125);

// Or use username, 10 is the count of videos to return.
$scraper->user->videos('iratee', 10);

All User Videos

$scraper->user->allVideos(123415125125);

// Or use username
$scraper->user->allVideos('iratee');

Specific User Video

$scraper->user->video('username', 123415125125);

Download User Video

/**
 * 1st Param: username
 * 2nd Param: video_id
 * 3rd Param: watermark (default true)
 * 4th Param: path to download
 */
$scraper->user->downloadVideo('username', 123415125125, true, './');

Discover

$scraper->discover->get('music');
$scraper->discover->get('user');
$scraper->discover->get('hashtag');

// Offset and count:

$scraper->general->discover('music', [
  'count' => 10,
  'offset' => 10
]);

Trending

// 25 being the number of items to return.
$scraper->trending->videos(25);

Music Data

// Gets data for music by id
$scraper->music->data(12312512512);

Music Videos

// Gets videos for music (25 being the count)
$scraper->music->videos(12124124124, 25)

Download Music by ID

/**
 * 1st Param: music_id
 * 2nd Param: path (optional)
 * 3rd Param: custom name (optional)
 */
$scraper->music->download(6821468236035541766, './', 'custom-name');

Hashtag Data

$scraper->hashtag->data('beatbox');

Hashtag Videos

// 30 being the count of videos to return
$scraper->hashtag->videos('beatbox', 30);

Signing a URL

2 methods of signing the URL is provided.

  1. You can use nodejs, this package will look to see if you have it installed, however, if you do not, it will attempt to install it.

  2. You can use the datafet.ch api that I have personally built to accept requests from anyone to sign a tiktok url. (This package handles it automatically if you set 'signMethod' => 'datafetch' in the configuration.)

$scraper->signUrl('TIKTOK_URL_HERE');

DataFetch API Key

DataFetch API does rate limit your requests at a max of 100 requests per 15 minutes. This can be avoided by obtaining an API key, which will then give you access to unlimited requests. You can obtain access by contacting me at matt [at] grubb [dot] com.

Errors

If anything error happens throughout the scraper, it will set the error at the following:

$scraper->error

Which will return the following structure:

[
  'error' => true,
  'message' => 'Detailed error message here.'
]

Also, the method you called will also return false.

If there was no error, two things you will notice:

  1. $scraper->error is set to false
  2. The method you called will not return false

Legal

This repo and it's contents are in no way affiliated with, authorized, maintained, sponsored or endorsed by TikTok or any of its affiliates or subsidiaries. This is an independent and unofficial package. Use at your own risk.

liballab/tiktok-php 适用场景与选型建议

liballab/tiktok-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「scraper」 「TikTok」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 liballab/tiktok-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 liballab/tiktok-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 liballab/tiktok-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-30