Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Access Denied Error When Downloading Video #44

Open
muchtoyearn opened this issue May 26, 2023 · 2 comments
Open

[QUESTION] Access Denied Error When Downloading Video #44

muchtoyearn opened this issue May 26, 2023 · 2 comments
Labels
duplicate This issue or pull request already exists question Further information is requested

Comments

@muchtoyearn
Copy link

muchtoyearn commented May 26, 2023

Hello. I'm certain this is a simple issue of just passing through my s_v_web_id and tt_chain_token, but I'm having trouble doing so.

Basically the code runs without error, but I get an Access Denied error when trying to download a TikTok Video. What's the work around here?

import io
import glob
import os
import urllib.request
from os import path

import aiohttp
from tiktokapipy.async_api import AsyncTikTokAPI
from tiktokapipy.models.video import Video

link = "https://www.tiktok.com/@prestoneckhardt/video/7203852306889133358"
directory = r"C:\Users\peckh\Desktop\ECKHARDT CAPITAL LLC"

async def save_video(video: Video):
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0;Win64) AppleWebkit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36'}
    async with aiohttp.ClientSession() as session:
        async with session.get(video.video.download_addr, headers=headers) as resp:
            data = await resp.read()
            print(data)  # print the response data
            with open(os.path.join(directory, f'{video.id}.mp4'), 'wb') as f:
                f.write(data)
            print(f"Video {video.id} has been downloaded.")

async def download_video():
    async with AsyncTikTokAPI() as api:
        video: Video = await api.video(link)
        if video.image_post:
            downloaded = await save_slideshow(video)
        else:
            downloaded = await save_video(video)

asyncio.run(download_video())```
@muchtoyearn muchtoyearn added the question Further information is requested label May 26, 2023
@Russell-Newton
Copy link
Owner

Russell-Newton commented May 26, 2023

TikTok doesn't seem to use the s_v_web_id token anymore. The tt_chain_token cookie and a referrer header is all you need.
The documentation includes a note for a workaround, provided in #35: https://tiktokpy.readthedocs.io/en/stable/users/usage.html#download-videos-and-slideshows.

If this doesn't work for you, please let me know.

Russell-Newton added a commit that referenced this issue Jun 15, 2023
* Create functions for executing API calls of 4 kinds:
    * comment/list/ - video comments
    * post/item_list/ - user posts
    * challenge/item_list/ - popular videos tagged with a challenge
    * related/item_list/ - videos related to this one

* Opens up potential future resolutions for #35, #38, #40, #43, and #44
@Russell-Newton Russell-Newton added the duplicate This issue or pull request already exists label Jul 5, 2023
@Russell-Newton
Copy link
Owner

This may be fixed in version 0.2.4 with the video download function. It doesn't work on slideshows and requires the optional yt-dlp dependency. This can be installed with pip install yt-dlp or pip install tiktokapipy[download]. It may not work 100% depending on where you are, but it works well for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants