-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlab.Rmd
executable file
·173 lines (101 loc) · 4.61 KB
/
lab.Rmd
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
---
title: "lab"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
pacman::p_load(tidyverse)
```
## Python browser
```{r}
b <- py$browser("test")
b$signature
`````
```{r}
dockeR::doc_copy("tiktoksignature", from = "../tiktok_signature/api.R", to_cont = "/usr/api.R")
dockeR::doc_copy("tiktoksignature", from = "../tiktok_signature/run_api.R", to_cont = "/usr/run_api.R")
```
## Get individual tiktok
```{r}
res <- parse_curl_request()
res$r_code
```
1. Install docker. Once it is installed you can verify with `docker -v```
2. Set `docker = T` in tk_auth() and run the following test:
```{r}
tk_init()
if(stringr::str_length(get_docker_signature("")) > 16){
message("Signature successfull, your docker container is working.")
} else {
message("Unable to get the signature")
}
```
4. Verify that everything is running correctly. The output should be a character vector of three elements.
## Docker Signature
```{r}
system("docker run -dt --rm --name tiktoksignature tiktoksignature:latest ")
res <- system("docker exec -t tiktoksignature /bin/python3 /usr/app/sign.py 'aa'", intern = T)
jsonlite::fromJSON(res)
system("docker start tiktapi")
# system("docker run -d -p 8080:8080 -v $(pwd):/usr/app --name tiktapi tiktapi")
system("docker run -d -p 8080:8080 -v $(pwd):/usr/app --name tiktapi tiktapi")
docker build . -t tiktokapi:latest
docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py
port <- 32770
res <- httr::POST(
url = glue::glue("http://localhost:{port}"),
body = "dd", timeout = httr::timeout(2))
rawToChar(res$content)
jsonlite::fromJSON(rawToChar(res$content))$signature
```
```{r}
query <- "mysterious_by_nature"
shape_url <- function(){
# base_url <- "https://m.tiktok.com/api/item_list/?aid=1988"
base_url <- "https://www.tiktok.com/node/share/user/@mysterious_by_nature?aid=1988"
# url_params$app_name <- "tiktok_web"
# url_params$device_platform <- "web"
# url_params$referer <- ""
# url_params$root_referer <- ""
# url_params$cookie_enabled <- "true"
# url_params$screen_width <- "1440"
# url_params$screen_height <- "900"
# url_params$browser_language <- "fr-FR"
# url_params$browser_platform <- "MacIntel"
# url_params$browser_online <- "true"
# url_params$ac <- "4g"
# url_params$timezone_name <- "America%2FToronto"
# url_params$priority_region <- ""
# url_params$appId <- "1233"
# url_params$region <- "CA"
#url_params$appType <- "m"
#url_params$isAndroid <- "true"
#url_params$isMobile <- "false"
#url_params$isIOS <- "false"
#url_params$OS <- "mac"
# url_params$language <- "fr"
# url_params$did <- "6893606546577982982"
# url_params$browser_name <- str_extract(ua, ".*?(?=\\/)")
# url_params$browser_version <- encode_string(str_remove(ua, ".*?\\/"))
# url_params$page_referer <- encode_string("https://www.tiktok.com/foryou")
## User Query
# url_params$uniqueId <- "mysterious_by_nature"
# url_params$secUid <- "MS4wLjABAAAAzoTMYqYafiGwnL-hR8DflXL6CSuvU5wDLmz5NdxchWbbR0XL7XuYWq-4XRb4_ldr"
# url_params$validUniqueId <- "mysterious_by_nature"
url_params <- list()
url_params$id <- "6727327145951183878"
url_params$secUid <- "MS4wLjABAAAA8ezUaW4ecJX222ObGXxt07F9BIh4QH3-g1P1DHyChT2LLi2cn-vAE2R53-H672ZO"
url_params$count <- "50"
url_params$maxCursor <- "1604716686000"
url_params$minCursor <- "0"
url_params$sourceType <- "8"
ua <- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
url_params$user_agent <- encode_string(ua)
url_params$verifyFp <- paste0("verify_", get_verify())
query <- url_params %>% imap_chr(~paste0("&", .y, "=", .x)) %>% paste(collapse = "") %>% paste0(base_url, .)
final_url <- get_signature(url, ua = ua, port = NULL)
tiktok_res <- httr::GET(final_url, httr::add_headers(.headers = c("user-agent" = ua)))
jsonlite::fromJSON(rawToChar(tiktok_res$content))
user_posts <- tk_posts(scope = "user", query = "willsmith", n = 50)
}
````