1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
|
%global _empty_manifest_terminate_build 0
Name: python-TikTokApi
Version: 5.2.2
Release: 1
Summary: The Unofficial TikTok API Wrapper in Python 3.
License: MIT
URL: https://github.com/davidteather/tiktok-api
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/a3/d7/422a5ef0a1caea158dc8ce5ead529c0940a340d8a0dacd84e41cfda2fee9/TikTokApi-5.2.2.tar.gz
BuildArch: noarch
%description
# Unofficial TikTok API in Python
This is an unofficial api wrapper for TikTok.com in python. With this api you are able to call most trending and fetch specific user information as well as much more.
[](https://zenodo.org/badge/latestdoi/188710490) [](https://www.linkedin.com/in/davidteather/) [](https://github.com/sponsors/davidteather) [](https://github.com/davidteather/TikTok-Api/releases) [](https://github.com/davidteather/TikTok-Api/actions/workflows/package-test.yml) [](https://github.com/davidteather/TikTok-Api/blob/master/LICENSE) [](https://pypi.org/project/TikTokApi/)  [](https://discord.gg/yyPhbfma6f)
## Sponsors
These sponsors have paid to be placed here and beyond that I do not have any affiliation with them, the TikTokAPI package will always be free and open-source. If you wish to be a sponsor of this project check out my [GitHub sponsors page](https://github.com/sponsors/davidteather).
<div align="center">
<p>
<a href="https://tikapi.io/?ref=davidteather" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/davidteather/TikTok-Api/master/imgs/tikapi.png" width="100" alt="TikApi">
</div>
<b></b>
<div>
<b>TikAPI</b> is a paid TikTok API service providing a full out-of-the-box solution, making life easier for developers — trusted by 500+ companies.
</div>
</a>
</p>
</div>
<br>
<div align="center">
<p>
<a href="https://trendpop.social/?ref=github-davidteather-tiktokapi" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/davidteather/TikTok-Api/master/imgs/trendpop.png" width="100" alt="Trendpop">
</div>
<div>
Trendpop builds software to help creators and businesses go viral on social video platforms.
</div>
<div>
<sub>
Excited about building in this space?
<a href="https://trendpop.social/careers?ref=github-davidteather-tiktokapi">
<sub>We're hiring engineers across all roles</sub>
</a>
<a href="https://trendpop.social/careers?ref=github-davidteather-tiktokapi" target="_blank">
<sub>- shoot us a message at </sub>
</a>
<a href="mailto:founders@trendpop.social" target="_blank">
<sub><code>founders@trendpop.social</code></sub>
</a>
</sub>
</div>
</a>
</p>
</div>
<br>
<div align="center">
<p>
<a href="https://influencerhunters.com/docs.html?utm_source=github&utm_medium=githubpage&utm_campaign=david_thea_github&utm_id=david_t" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/andrearama/TikTok-Api/master/imgs/IH_LOGO.png" width="100" alt="IH_logo">
</div>
<b></b>
<div>
TikTok data through APIs, providing 10+ Million posts / day to the largest Marketing and Social listening platforms.
</div>
</a>
</p>
</div>
## Table of Contents
- [Documentation](#documentation)
- [Getting Started](#getting-started)
- [How to Support The Project](#how-to-support-the-project)
- [Installing](#installing)
- [Common Issues](#common-issues)
- [Quick Start Guide](#quick-start-guide)
- [Examples](https://github.com/davidteather/TikTok-Api/tree/master/examples)
[**Upgrading from V4 to V5**](#upgrading-from-v4-to-v5)
## Documentation
You can find the full documentation [here](https://davidteather.github.io/TikTok-Api/docs/TikTokApi.html), the [TikTokApi Class](https://davidteather.github.io/TikTok-Api/docs/TikTokApi/tiktok.html) is where you'll probably spend most of your time.
## Getting Started
To get started using this api follow the instructions below.
**Note:** If you want to learn how to web scrape websites check my [free and open-source course for web scraping](https://github.com/davidteather/web-scraping-with-reverse-engineering)
### How to Support The Project
* Star the repo 😎
* Consider [sponsoring](https://github.com/sponsors/davidteather) me on GitHub
* Send me an email or a [LinkedIn](https://www.linkedin.com/in/davidteather/) message telling me what you're using the API for, I really like hearing what people are using it for.
* Submit PRs for issues :)
### Installing
If you run into an issue please check the closed issues on the github, although feel free to re-open a new issue if you find an issue that's been closed for a few months. The codebase can and does run into similar issues as it has before, because TikTok changes things up.
```sh
pip install TikTokApi
python -m playwright install
```
If you would prefer a video walk through of setting up this package [YouTube video](https://www.youtube.com/watch?v=-uCt1x8kINQ) just for that.
If you want a quick video to listen for [TikTok Live](https://www.youtube.com/watch?v=307ijmA3_lc) events in python.
#### Docker Installation
Clone this repository onto a local machine (or just the Dockerfile since it installs TikTokApi from pip) then run the following commands.
```sh
docker pull mcr.microsoft.com/playwright:focal
docker build . -t tiktokapi:latest
docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py
```
**Note** this assumes your script is named your_script.py and lives in the root of this directory.
### Common Issues
Please don't open an issue if you're experiencing one of these just comment if the provided solution do not work for you.
* **Browser Has no Attribute** - make sure you ran `python3 -m playwright install`, if your error persists try the [playwright-python](https://github.com/microsoft/playwright-python) quickstart guide and diagnose issues from there.
## Quick Start Guide
Here's a quick bit of code to get the most recent trending videos on TikTok. There's more examples in the [examples](https://github.com/davidteather/TikTok-Api/tree/master/examples) directory.
**Note:** If you want to learn how to web scrape websites check my [free and open-source course for web scraping](https://github.com/davidteather/web-scraping-with-reverse-engineering)
```py
from TikTokApi import TikTokApi
# Watch https://www.youtube.com/watch?v=-uCt1x8kINQ for a brief setup tutorial
with TikTokApi() as api:
for trending_video in api.trending.videos(count=50):
# Prints the author's username of the trending video.
print(trending_video.author.username)
```
**Note**: Jupyter (ipynb) only works on linux, see [microsoft/playwright-python #178](https://github.com/microsoft/playwright-python/issues/178)
To run the example scripts from the repository root, make sure you use the `-m` option on python.
```sh
python -m examples.get_trending
```
You can access the dictionary type of an object using `.as_dict`. On a video this may look like
[this](https://gist.github.com/davidteather/7c30780bbc30772ba11ec9e0b909e99d), although TikTok changes their structure from time to time so it's worth investigating the structure of the dictionary when you use this package.
## Upgrading from V4 to V5
All changes will be noted on [#803](https://github.com/davidteather/TikTok-Api/pull/803) if you want more information.
### Motivation
This package has been difficult to maintain due to it's structure, difficult to work with since the user of the package must write parsing methods to extract information from dictionaries, more memory intensive than it needs to be (although this can be further improved), and in general just difficult to work with for new users.
As a result, I've decided to at least attempt to remedy some of these issues, the biggest changes are that
1. The package has shifted to using classes for different TikTok objects resulting in an easier, higher-level programming experience.
2. All methods that used to return a list of objects have been switched to using iterators, to hopefully decrease memory utilization for most users.
### Upgrading Examples
#### Accessing Dictionary on Objects (similar to V4)
You'll probably need to use this beyond just for legacy support, since not all attributes are parsed out and attached
to the different objects.
You may want to use this as a workaround for legacy applications while you upgrade the rest of the app. I'd suggest that you do eventually upgrade to using the higher-level approach fully.
```py
user = api.user(username='therock')
user.as_dict # -> dict of the user_object
for video in user.videos():
video.as_dict # -> dict of TikTok's video object as found when requesting the videos endpoint
```
Here's a few more examples that help illustrate the differences in the flow of the usage of the package with V5.
```py
# V4
api = TikTokApi.get_instance()
trending_videos = api.by_trending()
#V5.1
with TikTokApi() as api: # .get_instance no longer exists
for trending_video in api.trending.videos():
# do something
```
Where in V4 you had to extract information yourself, the package now handles that for you. So it's much easier to do chained related function calls.
```py
# V4
trending_videos = api.by_trending()
for video in trending_videos:
# The dictionary responses are also different depending on what endpoint you got them from
# So, it's usually more painful than this to deal with
trending_user = api.get_user(id=video['author']['id'], secUid=video['author']['secUid'])
# V5
# This is more complicated than above, but it illustrates the simplified approach
for trending_video in api.trending.videos():
user_stats = trending_video.author.info_full['stats']
if user_stats['followerCount'] >= 10000:
# maybe save the user in a database
```
%package -n python3-TikTokApi
Summary: The Unofficial TikTok API Wrapper in Python 3.
Provides: python-TikTokApi
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-TikTokApi
# Unofficial TikTok API in Python
This is an unofficial api wrapper for TikTok.com in python. With this api you are able to call most trending and fetch specific user information as well as much more.
[](https://zenodo.org/badge/latestdoi/188710490) [](https://www.linkedin.com/in/davidteather/) [](https://github.com/sponsors/davidteather) [](https://github.com/davidteather/TikTok-Api/releases) [](https://github.com/davidteather/TikTok-Api/actions/workflows/package-test.yml) [](https://github.com/davidteather/TikTok-Api/blob/master/LICENSE) [](https://pypi.org/project/TikTokApi/)  [](https://discord.gg/yyPhbfma6f)
## Sponsors
These sponsors have paid to be placed here and beyond that I do not have any affiliation with them, the TikTokAPI package will always be free and open-source. If you wish to be a sponsor of this project check out my [GitHub sponsors page](https://github.com/sponsors/davidteather).
<div align="center">
<p>
<a href="https://tikapi.io/?ref=davidteather" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/davidteather/TikTok-Api/master/imgs/tikapi.png" width="100" alt="TikApi">
</div>
<b></b>
<div>
<b>TikAPI</b> is a paid TikTok API service providing a full out-of-the-box solution, making life easier for developers — trusted by 500+ companies.
</div>
</a>
</p>
</div>
<br>
<div align="center">
<p>
<a href="https://trendpop.social/?ref=github-davidteather-tiktokapi" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/davidteather/TikTok-Api/master/imgs/trendpop.png" width="100" alt="Trendpop">
</div>
<div>
Trendpop builds software to help creators and businesses go viral on social video platforms.
</div>
<div>
<sub>
Excited about building in this space?
<a href="https://trendpop.social/careers?ref=github-davidteather-tiktokapi">
<sub>We're hiring engineers across all roles</sub>
</a>
<a href="https://trendpop.social/careers?ref=github-davidteather-tiktokapi" target="_blank">
<sub>- shoot us a message at </sub>
</a>
<a href="mailto:founders@trendpop.social" target="_blank">
<sub><code>founders@trendpop.social</code></sub>
</a>
</sub>
</div>
</a>
</p>
</div>
<br>
<div align="center">
<p>
<a href="https://influencerhunters.com/docs.html?utm_source=github&utm_medium=githubpage&utm_campaign=david_thea_github&utm_id=david_t" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/andrearama/TikTok-Api/master/imgs/IH_LOGO.png" width="100" alt="IH_logo">
</div>
<b></b>
<div>
TikTok data through APIs, providing 10+ Million posts / day to the largest Marketing and Social listening platforms.
</div>
</a>
</p>
</div>
## Table of Contents
- [Documentation](#documentation)
- [Getting Started](#getting-started)
- [How to Support The Project](#how-to-support-the-project)
- [Installing](#installing)
- [Common Issues](#common-issues)
- [Quick Start Guide](#quick-start-guide)
- [Examples](https://github.com/davidteather/TikTok-Api/tree/master/examples)
[**Upgrading from V4 to V5**](#upgrading-from-v4-to-v5)
## Documentation
You can find the full documentation [here](https://davidteather.github.io/TikTok-Api/docs/TikTokApi.html), the [TikTokApi Class](https://davidteather.github.io/TikTok-Api/docs/TikTokApi/tiktok.html) is where you'll probably spend most of your time.
## Getting Started
To get started using this api follow the instructions below.
**Note:** If you want to learn how to web scrape websites check my [free and open-source course for web scraping](https://github.com/davidteather/web-scraping-with-reverse-engineering)
### How to Support The Project
* Star the repo 😎
* Consider [sponsoring](https://github.com/sponsors/davidteather) me on GitHub
* Send me an email or a [LinkedIn](https://www.linkedin.com/in/davidteather/) message telling me what you're using the API for, I really like hearing what people are using it for.
* Submit PRs for issues :)
### Installing
If you run into an issue please check the closed issues on the github, although feel free to re-open a new issue if you find an issue that's been closed for a few months. The codebase can and does run into similar issues as it has before, because TikTok changes things up.
```sh
pip install TikTokApi
python -m playwright install
```
If you would prefer a video walk through of setting up this package [YouTube video](https://www.youtube.com/watch?v=-uCt1x8kINQ) just for that.
If you want a quick video to listen for [TikTok Live](https://www.youtube.com/watch?v=307ijmA3_lc) events in python.
#### Docker Installation
Clone this repository onto a local machine (or just the Dockerfile since it installs TikTokApi from pip) then run the following commands.
```sh
docker pull mcr.microsoft.com/playwright:focal
docker build . -t tiktokapi:latest
docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py
```
**Note** this assumes your script is named your_script.py and lives in the root of this directory.
### Common Issues
Please don't open an issue if you're experiencing one of these just comment if the provided solution do not work for you.
* **Browser Has no Attribute** - make sure you ran `python3 -m playwright install`, if your error persists try the [playwright-python](https://github.com/microsoft/playwright-python) quickstart guide and diagnose issues from there.
## Quick Start Guide
Here's a quick bit of code to get the most recent trending videos on TikTok. There's more examples in the [examples](https://github.com/davidteather/TikTok-Api/tree/master/examples) directory.
**Note:** If you want to learn how to web scrape websites check my [free and open-source course for web scraping](https://github.com/davidteather/web-scraping-with-reverse-engineering)
```py
from TikTokApi import TikTokApi
# Watch https://www.youtube.com/watch?v=-uCt1x8kINQ for a brief setup tutorial
with TikTokApi() as api:
for trending_video in api.trending.videos(count=50):
# Prints the author's username of the trending video.
print(trending_video.author.username)
```
**Note**: Jupyter (ipynb) only works on linux, see [microsoft/playwright-python #178](https://github.com/microsoft/playwright-python/issues/178)
To run the example scripts from the repository root, make sure you use the `-m` option on python.
```sh
python -m examples.get_trending
```
You can access the dictionary type of an object using `.as_dict`. On a video this may look like
[this](https://gist.github.com/davidteather/7c30780bbc30772ba11ec9e0b909e99d), although TikTok changes their structure from time to time so it's worth investigating the structure of the dictionary when you use this package.
## Upgrading from V4 to V5
All changes will be noted on [#803](https://github.com/davidteather/TikTok-Api/pull/803) if you want more information.
### Motivation
This package has been difficult to maintain due to it's structure, difficult to work with since the user of the package must write parsing methods to extract information from dictionaries, more memory intensive than it needs to be (although this can be further improved), and in general just difficult to work with for new users.
As a result, I've decided to at least attempt to remedy some of these issues, the biggest changes are that
1. The package has shifted to using classes for different TikTok objects resulting in an easier, higher-level programming experience.
2. All methods that used to return a list of objects have been switched to using iterators, to hopefully decrease memory utilization for most users.
### Upgrading Examples
#### Accessing Dictionary on Objects (similar to V4)
You'll probably need to use this beyond just for legacy support, since not all attributes are parsed out and attached
to the different objects.
You may want to use this as a workaround for legacy applications while you upgrade the rest of the app. I'd suggest that you do eventually upgrade to using the higher-level approach fully.
```py
user = api.user(username='therock')
user.as_dict # -> dict of the user_object
for video in user.videos():
video.as_dict # -> dict of TikTok's video object as found when requesting the videos endpoint
```
Here's a few more examples that help illustrate the differences in the flow of the usage of the package with V5.
```py
# V4
api = TikTokApi.get_instance()
trending_videos = api.by_trending()
#V5.1
with TikTokApi() as api: # .get_instance no longer exists
for trending_video in api.trending.videos():
# do something
```
Where in V4 you had to extract information yourself, the package now handles that for you. So it's much easier to do chained related function calls.
```py
# V4
trending_videos = api.by_trending()
for video in trending_videos:
# The dictionary responses are also different depending on what endpoint you got them from
# So, it's usually more painful than this to deal with
trending_user = api.get_user(id=video['author']['id'], secUid=video['author']['secUid'])
# V5
# This is more complicated than above, but it illustrates the simplified approach
for trending_video in api.trending.videos():
user_stats = trending_video.author.info_full['stats']
if user_stats['followerCount'] >= 10000:
# maybe save the user in a database
```
%package help
Summary: Development documents and examples for TikTokApi
Provides: python3-TikTokApi-doc
%description help
# Unofficial TikTok API in Python
This is an unofficial api wrapper for TikTok.com in python. With this api you are able to call most trending and fetch specific user information as well as much more.
[](https://zenodo.org/badge/latestdoi/188710490) [](https://www.linkedin.com/in/davidteather/) [](https://github.com/sponsors/davidteather) [](https://github.com/davidteather/TikTok-Api/releases) [](https://github.com/davidteather/TikTok-Api/actions/workflows/package-test.yml) [](https://github.com/davidteather/TikTok-Api/blob/master/LICENSE) [](https://pypi.org/project/TikTokApi/)  [](https://discord.gg/yyPhbfma6f)
## Sponsors
These sponsors have paid to be placed here and beyond that I do not have any affiliation with them, the TikTokAPI package will always be free and open-source. If you wish to be a sponsor of this project check out my [GitHub sponsors page](https://github.com/sponsors/davidteather).
<div align="center">
<p>
<a href="https://tikapi.io/?ref=davidteather" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/davidteather/TikTok-Api/master/imgs/tikapi.png" width="100" alt="TikApi">
</div>
<b></b>
<div>
<b>TikAPI</b> is a paid TikTok API service providing a full out-of-the-box solution, making life easier for developers — trusted by 500+ companies.
</div>
</a>
</p>
</div>
<br>
<div align="center">
<p>
<a href="https://trendpop.social/?ref=github-davidteather-tiktokapi" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/davidteather/TikTok-Api/master/imgs/trendpop.png" width="100" alt="Trendpop">
</div>
<div>
Trendpop builds software to help creators and businesses go viral on social video platforms.
</div>
<div>
<sub>
Excited about building in this space?
<a href="https://trendpop.social/careers?ref=github-davidteather-tiktokapi">
<sub>We're hiring engineers across all roles</sub>
</a>
<a href="https://trendpop.social/careers?ref=github-davidteather-tiktokapi" target="_blank">
<sub>- shoot us a message at </sub>
</a>
<a href="mailto:founders@trendpop.social" target="_blank">
<sub><code>founders@trendpop.social</code></sub>
</a>
</sub>
</div>
</a>
</p>
</div>
<br>
<div align="center">
<p>
<a href="https://influencerhunters.com/docs.html?utm_source=github&utm_medium=githubpage&utm_campaign=david_thea_github&utm_id=david_t" target="_blank">
<div>
<img src="https://raw.githubusercontent.com/andrearama/TikTok-Api/master/imgs/IH_LOGO.png" width="100" alt="IH_logo">
</div>
<b></b>
<div>
TikTok data through APIs, providing 10+ Million posts / day to the largest Marketing and Social listening platforms.
</div>
</a>
</p>
</div>
## Table of Contents
- [Documentation](#documentation)
- [Getting Started](#getting-started)
- [How to Support The Project](#how-to-support-the-project)
- [Installing](#installing)
- [Common Issues](#common-issues)
- [Quick Start Guide](#quick-start-guide)
- [Examples](https://github.com/davidteather/TikTok-Api/tree/master/examples)
[**Upgrading from V4 to V5**](#upgrading-from-v4-to-v5)
## Documentation
You can find the full documentation [here](https://davidteather.github.io/TikTok-Api/docs/TikTokApi.html), the [TikTokApi Class](https://davidteather.github.io/TikTok-Api/docs/TikTokApi/tiktok.html) is where you'll probably spend most of your time.
## Getting Started
To get started using this api follow the instructions below.
**Note:** If you want to learn how to web scrape websites check my [free and open-source course for web scraping](https://github.com/davidteather/web-scraping-with-reverse-engineering)
### How to Support The Project
* Star the repo 😎
* Consider [sponsoring](https://github.com/sponsors/davidteather) me on GitHub
* Send me an email or a [LinkedIn](https://www.linkedin.com/in/davidteather/) message telling me what you're using the API for, I really like hearing what people are using it for.
* Submit PRs for issues :)
### Installing
If you run into an issue please check the closed issues on the github, although feel free to re-open a new issue if you find an issue that's been closed for a few months. The codebase can and does run into similar issues as it has before, because TikTok changes things up.
```sh
pip install TikTokApi
python -m playwright install
```
If you would prefer a video walk through of setting up this package [YouTube video](https://www.youtube.com/watch?v=-uCt1x8kINQ) just for that.
If you want a quick video to listen for [TikTok Live](https://www.youtube.com/watch?v=307ijmA3_lc) events in python.
#### Docker Installation
Clone this repository onto a local machine (or just the Dockerfile since it installs TikTokApi from pip) then run the following commands.
```sh
docker pull mcr.microsoft.com/playwright:focal
docker build . -t tiktokapi:latest
docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py
```
**Note** this assumes your script is named your_script.py and lives in the root of this directory.
### Common Issues
Please don't open an issue if you're experiencing one of these just comment if the provided solution do not work for you.
* **Browser Has no Attribute** - make sure you ran `python3 -m playwright install`, if your error persists try the [playwright-python](https://github.com/microsoft/playwright-python) quickstart guide and diagnose issues from there.
## Quick Start Guide
Here's a quick bit of code to get the most recent trending videos on TikTok. There's more examples in the [examples](https://github.com/davidteather/TikTok-Api/tree/master/examples) directory.
**Note:** If you want to learn how to web scrape websites check my [free and open-source course for web scraping](https://github.com/davidteather/web-scraping-with-reverse-engineering)
```py
from TikTokApi import TikTokApi
# Watch https://www.youtube.com/watch?v=-uCt1x8kINQ for a brief setup tutorial
with TikTokApi() as api:
for trending_video in api.trending.videos(count=50):
# Prints the author's username of the trending video.
print(trending_video.author.username)
```
**Note**: Jupyter (ipynb) only works on linux, see [microsoft/playwright-python #178](https://github.com/microsoft/playwright-python/issues/178)
To run the example scripts from the repository root, make sure you use the `-m` option on python.
```sh
python -m examples.get_trending
```
You can access the dictionary type of an object using `.as_dict`. On a video this may look like
[this](https://gist.github.com/davidteather/7c30780bbc30772ba11ec9e0b909e99d), although TikTok changes their structure from time to time so it's worth investigating the structure of the dictionary when you use this package.
## Upgrading from V4 to V5
All changes will be noted on [#803](https://github.com/davidteather/TikTok-Api/pull/803) if you want more information.
### Motivation
This package has been difficult to maintain due to it's structure, difficult to work with since the user of the package must write parsing methods to extract information from dictionaries, more memory intensive than it needs to be (although this can be further improved), and in general just difficult to work with for new users.
As a result, I've decided to at least attempt to remedy some of these issues, the biggest changes are that
1. The package has shifted to using classes for different TikTok objects resulting in an easier, higher-level programming experience.
2. All methods that used to return a list of objects have been switched to using iterators, to hopefully decrease memory utilization for most users.
### Upgrading Examples
#### Accessing Dictionary on Objects (similar to V4)
You'll probably need to use this beyond just for legacy support, since not all attributes are parsed out and attached
to the different objects.
You may want to use this as a workaround for legacy applications while you upgrade the rest of the app. I'd suggest that you do eventually upgrade to using the higher-level approach fully.
```py
user = api.user(username='therock')
user.as_dict # -> dict of the user_object
for video in user.videos():
video.as_dict # -> dict of TikTok's video object as found when requesting the videos endpoint
```
Here's a few more examples that help illustrate the differences in the flow of the usage of the package with V5.
```py
# V4
api = TikTokApi.get_instance()
trending_videos = api.by_trending()
#V5.1
with TikTokApi() as api: # .get_instance no longer exists
for trending_video in api.trending.videos():
# do something
```
Where in V4 you had to extract information yourself, the package now handles that for you. So it's much easier to do chained related function calls.
```py
# V4
trending_videos = api.by_trending()
for video in trending_videos:
# The dictionary responses are also different depending on what endpoint you got them from
# So, it's usually more painful than this to deal with
trending_user = api.get_user(id=video['author']['id'], secUid=video['author']['secUid'])
# V5
# This is more complicated than above, but it illustrates the simplified approach
for trending_video in api.trending.videos():
user_stats = trending_video.author.info_full['stats']
if user_stats['followerCount'] >= 10000:
# maybe save the user in a database
```
%prep
%autosetup -n TikTokApi-5.2.2
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-TikTokApi -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 5.2.2-1
- Package Spec generated
|