Skip to content

Commit

Permalink
🌞🌻 V4.0.1 🌞 🌻
Browse files Browse the repository at this point in the history
* Fixed TikTokApi has no attribute .region
* Changed up tests to hopefully have CI pass more
* Add README to the doc generator
  • Loading branch information
davidteather authored Aug 7, 2021
2 parents f1597cd + 200b108 commit 1693455
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9]
os: [macos-latest]
python-version: [3.7, 3.9]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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.

[![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white&style=flat-square)](https://www.linkedin.com/in/davidteather/) [![Sponsor Me](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/davidteather) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/davidteather/TikTok-Api)](https://github.com/davidteather/TikTok-Api/releases) [![Build Status](https://travis-ci.com/davidteather/TikTok-Api.svg?branch=master)](https://travis-ci.com/davidteather/TikTok-Api) [![GitHub](https://img.shields.io/github/license/davidteather/TikTok-Api)](https://github.com/davidteather/TikTok-Api/blob/master/LICENSE) [![Downloads](https://pepy.tech/badge/tiktokapi)](https://pypi.org/project/TikTokApi/) ![](https://visitor-badge.laobi.icu/badge?page_id=davidteather.TikTok-Api) [![Support Server](https://img.shields.io/discord/783108952111579166.svg?color=7289da&logo=discord&style=flat-square)](https://discord.gg/yyPhbfma6f)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white&style=flat-square)](https://www.linkedin.com/in/davidteather/) [![Sponsor Me](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/davidteather) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/davidteather/TikTok-Api)](https://github.com/davidteather/TikTok-Api/releases) [![Build Status](https://img.shields.io/github/workflow/status/davidteather/tiktok-api/TikTokApi%20CI/master)](https://github.com/davidteather/TikTok-Api/actions/workflows/package-test.yml) [![GitHub](https://img.shields.io/github/license/davidteather/TikTok-Api)](https://github.com/davidteather/TikTok-Api/blob/master/LICENSE) [![Downloads](https://pepy.tech/badge/tiktokapi)](https://pypi.org/project/TikTokApi/) ![](https://visitor-badge.laobi.icu/badge?page_id=davidteather.TikTok-Api) [![Support Server](https://img.shields.io/discord/783108952111579166.svg?color=7289da&logo=discord&style=flat-square)](https://discord.gg/yyPhbfma6f)

## Thank you to our sponsors & advertisers

Expand Down Expand Up @@ -59,7 +59,7 @@ docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py

Please don't open an issue if you're experiencing one of these just comment if the provided solution do not work for you.

* **Has no Attribute .width** - make sure you ran `python3 -m playwright install`, if your error persists try the [playwright](https://github.com/microsoft/playwright-python) quickstart guide and diagnose issues from there.
* **Browser Has no Attribute** - make sure you ran `python3 -m playwright install`, if your error persists try the [playwright](https://github.com/microsoft/playwright-python) quickstart guide and diagnose issues from there.

## Quick Start Guide

Expand All @@ -68,14 +68,11 @@ Here's a quick bit of code to get the most recent trending on TikTok. There's mo
```py
from TikTokApi import TikTokApi
api = TikTokApi.get_instance()
# If playwright doesn't work for you try to use selenium
# api = TikTokApi.get_instance(use_selenium=True)

results = 10

# Since TikTok changed their API you need to use the custom_verifyFp option.
# In your web browser you will need to go to TikTok, Log in and get the s_v_web_id value.
trending = api.trending(count=results, custom_verifyFp="")
trending = api.by_trending(count=results, custom_verifyFp="")

for tiktok in trending:
# Prints the id of the tiktok
Expand All @@ -91,11 +88,11 @@ module form of python the interpreter
python -m examples.get_trending
```

[Here's](https://gist.github.com/davidteather/7c30780bbc30772ba11ec9e0b909e99d) an example of what a tiktok dictionary looks like.
[Here's](https://gist.github.com/davidteather/7c30780bbc30772ba11ec9e0b909e99d) an example of what a TikTok dictionary looks like.

## Documentation

You can find the documentation [here](https://davidteather.github.io/TikTok-Api/docs) (you'll likely just need the TikTokApi section of the docs), I will be making this documentation more complete overtime as it's not super great right now, but better than just having it in the readme!
You can find the documentation [here](https://davidteather.github.io/TikTok-Api/docs/TikTokApi.html) (you'll likely just need the TikTokApi section of the docs), I will be making this documentation more complete overtime as it's not super great right now, but better than just having it in the readme!

## Authors

Expand All @@ -105,4 +102,4 @@ See also the list of [contributors](https://github.com/davidteather/TikTok-Api/c

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
This project is licensed under the MIT License
5 changes: 5 additions & 0 deletions TikTokApi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
"""
.. include:: ../README.md
"""
__docformat__ = "restructuredtext"

from TikTokApi.tiktok import TikTokApi
from TikTokApi.tiktokuser import TikTokUser
32 changes: 15 additions & 17 deletions TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import random
import requests
import time
import logging
import json
from urllib.parse import urlencode, quote
from playwright.sync_api import sync_playwright
import string
import logging
import os
from .utilities import update_messager
import random
import string
import time
from urllib.parse import quote, urlencode

import requests
from playwright.sync_api import sync_playwright

from .exceptions import *
from .utilities import update_messager


os.environ["no_proxy"] = "127.0.0.1,localhost"
Expand Down Expand Up @@ -72,18 +73,16 @@ def __init__(self, **kwargs):
self.region = self.browser.region
self.language = self.browser.language
except Exception as e:
logging.error(e)
logging.warning(
"An error ocurred while opening your browser but it was ignored."
)
logging.exception(e)
logging.warning("An error ocurred while opening your browser but it was ignored.")
logging.warning("Are you sure you ran python -m playwright install")

self.timezone_name = ""
self.browser_language = ""
self.browser_platform = ""
self.browser_name = ""
self.browser_version = ""
self.width = "1920"
self.height = "1080"
self.region = "US"
self.language = "en"

@staticmethod
def get_instance(**kwargs):
Expand Down Expand Up @@ -1651,7 +1650,6 @@ def __add_url_params__(self) -> str:
"aid": 1988,
"app_name": "tiktok_web",
"device_platform": "web_mobile",
# "device_id": random.randint(),
"region": self.region or "US",
"priority_region": "",
"os": "ios",
Expand All @@ -1663,7 +1661,7 @@ def __add_url_params__(self) -> str:
"browser_language": self.browser_language.lower() or "en-us",
"browser_platform": "iPhone",
"browser_name": "Mozilla",
"browser_version": self.__format_new_params__(self.userAgent), # Ex: 5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Mobile/15E148 Safari/604.1
"browser_version": self.__format_new_params__(self.userAgent),
"browser_online": "true",
"timezone_name": self.timezone_name or "America/Chicago",
"is_page_visible": "true",
Expand Down
145 changes: 143 additions & 2 deletions docs/TikTokApi.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@
pattern=".+" required>


<h2>Contents</h2>
<ul>
<li><a href="#unofficial-tiktok-api-in-python">Unofficial TikTok API in Python</a>
<ul>
<li><a href="#thank-you-to-our-sponsors-advertisers">Thank you to our sponsors &amp; advertisers</a></li>
<li><a href="#table-of-contents">Table of Contents</a></li>
<li><a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#how-to-support-the-project">How to support the project</a></li>
</ul></li>
<li><a href="#installing">Installing</a>
<ul>
<li><a href="#docker-installation">Docker Installation</a></li>
</ul></li>
<li><a href="#common-issues">Common Issues</a></li>
<li><a href="#quick-start-guide">Quick Start Guide</a></li>
<li><a href="#documentation">Documentation</a></li>
<li><a href="#authors">Authors</a></li>
<li><a href="#license">License</a></li>
</ul></li>
</ul>


<h2>Submodules</h2>
<ul>
Expand All @@ -54,10 +76,129 @@ <h2>Submodules</h2>
<h1 class="modulename">
TikTokApi </h1>


<div class="docstring"><h1 id="unofficial-tiktok-api-in-python">Unofficial TikTok API in Python</h1>

<p>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.</p>

<p><a href="https://www.linkedin.com/in/davidteather/"><img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&amp;logo=linkedin&amp;logoColor=white&amp;style=flat-square" alt="LinkedIn" /></a> <a href="https://github.com/sponsors/davidteather"><img src="https://img.shields.io/static/v1?label=Sponsor&amp;message=%E2%9D%A4&amp;logo=GitHub" alt="Sponsor Me" /></a> <a href="https://github.com/davidteather/TikTok-Api/releases"><img src="https://img.shields.io/github/v/release/davidteather/TikTok-Api" alt="GitHub release (latest by date)" /></a> <a href="https://github.com/davidteather/TikTok-Api/actions/workflows/package-test.yml"><img src="https://img.shields.io/github/workflow/status/davidteather/tiktok-api/TikTokApi%20CI/master" alt="Build Status" /></a> <a href="https://github.com/davidteather/TikTok-Api/blob/master/LICENSE"><img src="https://img.shields.io/github/license/davidteather/TikTok-Api" alt="GitHub" /></a> <a href="https://pypi.org/project/TikTokApi/"><img src="https://pepy.tech/badge/tiktokapi" alt="Downloads" /></a> <img src="https://visitor-badge.laobi.icu/badge?page_id=davidteather.TikTok-Api" alt="" /> <a href="https://discord.gg/yyPhbfma6f"><img src="https://img.shields.io/discord/783108952111579166.svg?color=7289da&amp;logo=discord&amp;style=flat-square" alt="Support Server" /></a></p>

<h2 id="thank-you-to-our-sponsors-advertisers">Thank you to our sponsors &amp; advertisers</h2>

<p><a href="https://tikapi.io/?ref=davidteather"><img src="imgs/logo128.png" alt="TikAPI" /></a> | <strong><a href="https://tikapi.io/?ref=davidteather">TikAPI</a></strong> is a paid TikTok API service providing an full out-of-the-box solution for developers, trusted by 100+ companies. <a href="https://tikapi.io/?ref=davidteather">Learn more</a>
:-------------------------:|:-------------------------:</p>

<h2 id="table-of-contents">Table of Contents</h2>

<ul>
<li><a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#installing">Installing</a></li>
<li><a href="#common-issues">Common Issues</a></li>
</ul></li>
<li><a href="#quick-start-guide">Quick Start Guide</a>
<ul>
<li><a href="https://github.com/davidteather/TikTok-Api/tree/master/examples">Examples</a></li>
</ul></li>
<li><a href="#documentation">Documentation</a></li>
<li><a href="#built-with">Built With</a></li>
<li><a href="#authors">Authors</a></li>
<li><a href="#license">License</a></li>
</ul>

<h2 id="getting-started">Getting Started</h2>

<p>To get started using this api follow the instructions below.</p>

<h4 id="how-to-support-the-project">How to support the project</h4>

<ul>
<li>Feel free to sponsor me on GitHub</li>
<li>Feel free to tip the project using the brave browser</li>
<li>Submit PRs for issues :)</li>
</ul>

<h3 id="installing">Installing</h3>

<p>If you run into an issue please check the closed issues on the github. You're most likely not the first person to experience this issue. If nothing works feel free to open an issue.</p>

<div class="codehilite"><pre><span></span><code>pip install TikTokApi
python -m playwright install
</code></pre></div>

<p>If you would prefer a video walk through of setting up this package I created a <a href="https://www.youtube.com/watch?v=zwLmLfVI-VQ">YouTube video</a> just for that.</p>

<p>If you're on MacOS you may need to install <a href="https://webkit.org/build-tools/">XCode Developer Tools</a></p>

<h4 id="docker-installation">Docker Installation</h4>

<p>Clone this repository onto a local machine then run the following commands.</p>

<div class="codehilite"><pre><span></span><code>docker build . -t tiktokapi:latest
docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py
</code></pre></div>

<p><strong>Note</strong> this assumes your script is named your_script.py and lives in the root of this directory.</p>

<h3 id="common-issues">Common Issues</h3>

<p>Please don't open an issue if you're experiencing one of these just comment if the provided solution do not work for you.</p>

<ul>
<li><strong>Browser Has no Attribute</strong> - make sure you ran <code>python3 -m playwright install</code>, if your error persists try the <a href="https://github.com/microsoft/playwright-python">playwright</a> quickstart guide and diagnose issues from there.</li>
</ul>

<h2 id="quick-start-guide">Quick Start Guide</h2>

<p>Here's a quick bit of code to get the most recent trending on TikTok. There's more examples in the examples directory.</p>

<div class="codehilite"><pre><span></span><code><span class="kn">from</span> <span class="nn">TikTokApi</span> <span class="kn">import</span> <span class="n">TikTokApi</span>
<span class="n">api</span> <span class="o">=</span> <span class="n">TikTokApi</span><span class="o">.</span><span class="n">get_instance</span><span class="p">()</span>
<span class="n">results</span> <span class="o">=</span> <span class="mi">10</span>

<span class="c1"># Since TikTok changed their API you need to use the custom_verifyFp option. </span>
<span class="c1"># In your web browser you will need to go to TikTok, Log in and get the s_v_web_id value.</span>
<span class="n">trending</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">by_trending</span><span class="p">(</span><span class="n">count</span><span class="o">=</span><span class="n">results</span><span class="p">,</span> <span class="n">custom_verifyFp</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">)</span>

<span class="k">for</span> <span class="n">tiktok</span> <span class="ow">in</span> <span class="n">trending</span><span class="p">:</span>
<span class="c1"># Prints the id of the tiktok</span>
<span class="nb">print</span><span class="p">(</span><span class="n">tiktok</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">])</span>

<span class="nb">print</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">trending</span><span class="p">))</span>
</code></pre></div>

<p>To run the example scripts from the repository root, make sure you use the
module form of python the interpreter</p>

<div class="codehilite"><pre><span></span><code>python -m examples.get_trending
</code></pre></div>

<p><a href="https://gist.github.com/davidteather/7c30780bbc30772ba11ec9e0b909e99d">Here's</a> an example of what a TikTok dictionary looks like.</p>

<h2 id="documentation">Documentation</h2>

<p>You can find the documentation <a href="https://davidteather.github.io/TikTok-Api/docs/TikTokApi.html">here</a> (you'll likely just need the TikTokApi section of the docs), I will be making this documentation more complete overtime as it's not super great right now, but better than just having it in the readme!</p>

<h2 id="authors">Authors</h2>

<ul>
<li><strong>David Teather</strong> - <em>Initial work</em> - <a href="https://github.com/davidteather">davidteather</a></li>
</ul>

<p>See also the list of <a href="https://github.com/davidteather/TikTok-Api/contributors">contributors</a> who participated in this project.</p>

<h2 id="license">License</h2>

<p>This project is licensed under the MIT License</p>
</div>

<details>
<summary>View Source</summary>
<div class="codehilite"><pre><span></span><span class="kn">from</span> <span class="nn">TikTokApi.tiktok</span> <span class="kn">import</span> <span class="n">TikTokApi</span>
<div class="codehilite"><pre><span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">.. include:: ../README.md</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="n">__docformat__</span> <span class="o">=</span> <span class="s2">&quot;restructuredtext&quot;</span>

<span class="kn">from</span> <span class="nn">TikTokApi.tiktok</span> <span class="kn">import</span> <span class="n">TikTokApi</span>
<span class="kn">from</span> <span class="nn">TikTokApi.tiktokuser</span> <span class="kn">import</span> <span class="n">TikTokUser</span>
</pre></div>

Expand Down
Loading

0 comments on commit 1693455

Please sign in to comment.