feat: added page as a replacement for the cursor
This commit is contained in:
parent
1174110492
commit
5d7b5388dc
@ -103,6 +103,7 @@ const username = "tobz2k19"
|
||||
|
||||
Tiktok.Search(username, {
|
||||
type: "user",
|
||||
page: 1,
|
||||
cookie: process.env.COOKIE || "Your Cookie"
|
||||
}).then((result) => {
|
||||
console.log(result)
|
||||
|
||||
@ -35,6 +35,46 @@ export const _userPostsParams = () => {
|
||||
)
|
||||
}
|
||||
|
||||
export const _userSearchParams = (keyword: any, page: number = 1) => {
|
||||
let cursor = 0
|
||||
for (let i = 1; i < page; i++) {
|
||||
cursor += 10
|
||||
}
|
||||
|
||||
return qs.stringify({
|
||||
WebIdLastTime: Date.now(),
|
||||
aid: "1988",
|
||||
app_language: "en",
|
||||
app_name: "tiktok_web",
|
||||
browser_language: "en-US",
|
||||
browser_name: "Mozilla",
|
||||
browser_online: true,
|
||||
browser_platform: "Win32",
|
||||
browser_version: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
|
||||
channel: "tiktok_web",
|
||||
cookie_enabled: true,
|
||||
cursor: cursor,
|
||||
device_id: "7340508178566366722",
|
||||
device_platform: "web_pc",
|
||||
focus_state: false,
|
||||
from_page: "search",
|
||||
history_len: 5,
|
||||
is_fullscreen: false,
|
||||
is_page_visible: true,
|
||||
keyword: keyword,
|
||||
os: "windows",
|
||||
priority_region: "ID",
|
||||
referer: "",
|
||||
region: "ID",
|
||||
screen_height: 768,
|
||||
screen_width: 1366,
|
||||
search_id: "20240329123238075BE0FECBA0FE11C76B",
|
||||
tz_name: "Asia/Jakarta",
|
||||
web_search_code: { tiktok: { client_params_x: { search_engine: { ies_mt_user_live_video_card_use_libra: 1, mt_search_general_user_live_card: 1 } }, search_server: {} } },
|
||||
webcast_language: "en"
|
||||
})
|
||||
}
|
||||
|
||||
export const _tiktokApiParams = (args: any) => {
|
||||
return {
|
||||
...args,
|
||||
|
||||
10
src/index.ts
10
src/index.ts
@ -38,10 +38,10 @@ export const Tiktok = {
|
||||
}
|
||||
}
|
||||
},
|
||||
Search: async <T extends "user" | "video">(query: string, options: { type: T; cookie: string }): Promise<TiktokSearchResponse<T>> => {
|
||||
Search: async <T extends "user" | "video">(query: string, options: { type: T; cookie?: string; page?: number }): Promise<TiktokSearchResponse<T>> => {
|
||||
switch (options?.type) {
|
||||
case "user": {
|
||||
const response = await SearchUser(query, options.cookie)
|
||||
const response = await SearchUser(query, options?.cookie, options?.page)
|
||||
return response as TiktokSearchResponse<T>
|
||||
}
|
||||
// case "video": {
|
||||
@ -49,13 +49,13 @@ export const Tiktok = {
|
||||
// return response as TiktokSearchResponse<T>
|
||||
// }
|
||||
default: {
|
||||
const response = await SearchUser(query, options?.cookie)
|
||||
const response = await SearchUser(query, options?.cookie, options?.page)
|
||||
return response as TiktokSearchResponse<T>
|
||||
}
|
||||
}
|
||||
},
|
||||
StalkUser: async (username: string, options: { cookie: string }): Promise<StalkResult> => {
|
||||
const response = await StalkUser(username, options.cookie)
|
||||
StalkUser: async (username: string, options?: { cookie?: string }): Promise<StalkResult> => {
|
||||
const response = await StalkUser(username, options?.cookie)
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,51 +1,19 @@
|
||||
import Axios from "axios"
|
||||
import { _tiktokSearchUserFull, _tiktokurl } from "../../constants/api"
|
||||
import { TiktokUserSearchResponse } from "../../types/search/userSearch"
|
||||
|
||||
const params = (keyword: string) => {
|
||||
return {
|
||||
WebIdLastTime: Date.now(),
|
||||
aid: "1988",
|
||||
app_language: "en",
|
||||
app_name: "tiktok_web",
|
||||
browser_language: "en-US",
|
||||
browser_name: "Mozilla",
|
||||
browser_online: true,
|
||||
browser_platform: "Win32",
|
||||
browser_version: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
|
||||
channel: "tiktok_web",
|
||||
cookie_enabled: true,
|
||||
cursor: 0,
|
||||
device_id: "7340508178566366722",
|
||||
device_platform: "web_pc",
|
||||
focus_state: false,
|
||||
from_page: "search",
|
||||
history_len: 5,
|
||||
is_fullscreen: false,
|
||||
is_page_visible: true,
|
||||
keyword: keyword,
|
||||
os: "windows",
|
||||
priority_region: "ID",
|
||||
referer: "",
|
||||
region: "ID",
|
||||
screen_height: 768,
|
||||
screen_width: 1366,
|
||||
tz_name: "Asia/Jakarta",
|
||||
web_search_code: { tiktok: { client_params_x: { search_engine: { ies_mt_user_live_video_card_use_libra: 1, mt_search_general_user_live_card: 1 } }, search_server: {} } },
|
||||
webcast_language: "en"
|
||||
}
|
||||
}
|
||||
import { _userSearchParams } from "../../constants/params"
|
||||
|
||||
/**
|
||||
* Tiktok Search User
|
||||
* @param {string} username - The username you want to search
|
||||
* @param {object|string} cookie - Your Tiktok cookie (optional)
|
||||
* @param {number} page - The page you want to search (optional)
|
||||
* @returns {Promise<TiktokUserSearchResponse>}
|
||||
*/
|
||||
|
||||
export const SearchUser = (username: string, cookie?: any): Promise<TiktokUserSearchResponse> =>
|
||||
export const SearchUser = (username: string, cookie?: any, page?: number): Promise<TiktokUserSearchResponse> =>
|
||||
new Promise(async (resolve, reject) => {
|
||||
Axios(_tiktokSearchUserFull(params(username)), {
|
||||
Axios(_tiktokSearchUserFull(_userSearchParams(username, page)), {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user