Skip to content

Commit 18b836a

Browse files
committed
update
Signed-off-by: ふぁ <yuki@yuki0311.com>
1 parent d6284ee commit 18b836a

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ python TwitterFrontendFlow/sample2.py
6262

6363
## Fast development of modules using this document
6464

65-
```python
66-
67-
68-
```
69-
65+
...
7066
Can also be used in combination with [TwitterInternalAPIDocument](https://github.com/fa0311/TwitterInternalAPIDocument)
7167

7268
## Reference

lib/graphql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def to_api(graphql_output: list, kwargs: dict) -> dict:
165165
features[key] = variable_converter.get(switch["value"])
166166

167167
api_output["graphql"][exports["operationName"]] = {
168-
"url": "https://twitter.com/i/api/graphql/{queryId}/{operationName}".format(
168+
"url": "https://api.twitter.com/graphql/{queryId}/{operationName}".format(
169169
**exports
170170
),
171171
"queryId": exports["queryId"],

lib/md.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def gen_md_graphql(graphql_output: list) -> md_generator:
5353
md.h2(exports["operationName"])
5454
md.p("Request URL", end=": ")
5555
md.inline(
56-
"https://twitter.com/i/api/graphql/{queryId}/{operationName}".format(
56+
"https://api.twitter.com/graphql/{queryId}/{operationName}".format(
5757
**exports
5858
)
5959
)

sample.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import requests
2+
import json
3+
4+
api = requests.get(
5+
"https://raw.githubusercontent.com/fa0311/TwitterInternalAPIDocument/develop/docs/json/API.json"
6+
).json()
7+
8+
# Always use new APIs
9+
# api = requests.get("https://github.com/fa0311/TwitterInternalAPIDocument/blob/master/docs/json/API.json").json()
10+
11+
headers=api["header"]
12+
session = requests.session()
13+
session.get("https://twitter.com/", headers={"User-Agent": headers["User-Agent"]})
14+
x_guest_token = session.post("https://api.twitter.com/1.1/guest/activate.json",headers=headers).json()["guest_token"]
15+
headers.update({
16+
"Content-type": "application/json",
17+
"x-guest-token": x_guest_token,
18+
"x-twitter-active-user": "yes",
19+
"x-twitter-client-language": "en",
20+
})
21+
22+
# <Recommendation> You can also use TwitterFrontendFlow
23+
# flow = TwitterFrontendFlow()
24+
# session = flow.session
25+
# x_guest_token = flow.x_guest_token
26+
27+
# API you want to use
28+
operationName = "UserTweets"
29+
30+
# variables must be entered by yourself
31+
variables = {
32+
"userId": "900282258736545792",
33+
"count": 40,
34+
"includePromotedContent": True,
35+
"withQuickPromoteEligibilityTweetFields": True,
36+
"withSuperFollowsUserFields": True,
37+
"withDownvotePerspective": False,
38+
"withReactionsMetadata": False,
39+
"withReactionsPerspective": False,
40+
"withSuperFollowsTweetFields": True,
41+
"withVoice": True,
42+
"withV2Timeline": True,
43+
}
44+
45+
data = api["graphql"][operationName]
46+
parameters = {
47+
"queryId": data["queryId"],
48+
"variables": json.dumps(variables),
49+
"features": json.dumps(data["features"]),
50+
}
51+
52+
data["url"] = "https://api.twitter.com/graphql/oPHs3ydu7ZOOy2f02soaPA/UserTweets"
53+
54+
55+
if data["method"] == "GET":
56+
response = session.get(data["url"],headers=headers, params=parameters).json()
57+
elif data["method"] == "POST":
58+
response = session.post(data["url"],headers=headers, json=parameters).json()
59+
60+
61+
print(response)

0 commit comments

Comments
 (0)