carcabot / tiktok-signature

Generate tiktok signature token using node
733 stars 283 forks source link

Get comment is empty #175

Closed liuyan345 closed 1 year ago

liuyan345 commented 1 year ago

I copied user-video.js to get videos comments, but the result was empty. I guess the header argument is missing. Here is my code

const Signer = require("../"); const axios = require("axios"); // NOTE: not adding this to package.json, you'll need to install it manually

// The username of your TikTok profile. const VIDEO_ID = "7174097352083492101";

const TT_REQ_USER_AGENT = "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36";

// This the final URL you make a request to for the API call, it is ALWAYS this, do not mistaken it for the signed URL const TT_REQ_PERM_URL = "https://www.tiktok.com/api/comment/list/?aid=1988&app_language=ja-JP&app_name=tiktok_web&aweme_id="+VIDEO_ID+"&battery_info=1&browser_language=zh-CN&browser_name=Mozilla&browser_online=true&browser_platform=MacIntel&browser_version=5.0%20%28Macintosh%3B%20Intel%20Mac%20OS%20X%2010_15_7%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F108.0.0.0%20Safari%2F537.36&channel=tiktok_web&cookie_enabled=true&count=20&current_region=JP&cursor=0&device_id=7166176930252047874&device_platform=web_pc&focus_state=true&fromWeb=1&from_page=video&history_len=3&is_fullscreen=false&is_page_visible=true&os=mac&priority_region=&referer=&region=AU&screen_height=1200&screen_width=1920&tz_name=Asia%2FShanghai&verifyFp=verify_lbbrtp31_G5Qh3rWz_uNAJ_4i1v_8I8M_ZWBnEhfxpjR2&webcast_language=zh-Hant-TW&msToken=VoMNOkP0ZwUHKn2-QN5bKl3DW-X8WvPshUkxCuV_QQjtndEzh1kehqSdUVPwmZ1HRSqomRQXcavRpfniXxy6CJdBbuzTALaofDCVTOhL6NmaLlWQp4LZ5ZZQftFZCVzxau_f3CZ_5wSoNRwBahE=&X-Bogus=DFSzswVuLXUANCohSdRQo5KMtaD/&_signature=_02B4Z6wo000010ftFwgAAIDCuaFrOAFElrNH7ROAALJ00d";

// If you're getting empty results change the verifyFp, msToken, X-Bogus and _signature params const queryParams = { aid: 1988, app_language: "ja-JP", app_name: "tiktok_web", aweme_id:VIDEO_ID, battery_info: 1, browser_language: "zh-CN", browser_name: "Mozilla", browser_online: true, browser_platform: "MacIntel", browser_version: "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", channel: "tiktok_web", cookie_enabled: true, count: 20, current_region: "JP", cursor: 0, device_id: 7166176930252047874, device_platform: "web_pc", focus_state: true, fromWeb: 1, from_page: "video", history_len: 3, is_fullscreen: false, is_page_visible: true, os: "mac", screen_height: 1200, screen_width: 1920, tz_name: "Asia/Shanghai", webcast_language: "zh-Hant-TW" };

async function main() { const signer = new Signer(null, TT_REQ_USER_AGENT); await signer.init();

const qsObject = new URLSearchParams(queryParams); const qs = qsObject.toString();

const unsignedUrl = https://m.tiktok.com/api/comment/list/?${qs};

const signature = await signer.sign(unsignedUrl); const navigator = await signer.navigator();

await signer.close();

const { "signed_url": signed_url } = signature; const { "x-tt-params": xTtParams } = signature; const { user_agent: userAgent } = navigator;

const res = await testApiReq({ userAgent, xTtParams,signed_url }); const { data } = res; console.log(data); }

async function testApiReq({ userAgent, xTtParams,signed_url }) { const options = { method: "GET", headers: { "referer":"https://www.tiktok.com/@atakangunerhan/video/7174097352083492101?is_copy_url=1&is_from_webapp=v1", "user-agent": userAgent, "x-tt-params": xTtParams, "Accept-Encoding": "gzip,deflate,compress" }, url: TT_REQ_PERM_URL, };

return axios(options); }

main();