twitter-openapi-typescript 0.0.35 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +12 -4
- package/cookies.json +156 -475
- package/dist/src/api.d.ts +7 -2
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/api.js +43 -17
- package/dist/src/api.js.map +1 -1
- package/dist/src/apis/defaultApi.js +2 -2
- package/dist/src/apis/postApi.d.ts.map +1 -1
- package/dist/src/apis/postApi.js +14 -11
- package/dist/src/apis/postApi.js.map +1 -1
- package/dist/src/apis/tweetApi.js +11 -11
- package/dist/src/apis/tweetApi.js.map +1 -1
- package/dist/src/apis/userApi.js +2 -2
- package/dist/src/apis/userListApi.js +2 -2
- package/dist/src/apis/userListApi.js.map +1 -1
- package/dist/src/apis/usersApi.js +2 -2
- package/dist/src/apis/v11PostApi.js +2 -2
- package/dist/src/utils/api.d.ts.map +1 -1
- package/dist/src/utils/api.js.map +1 -1
- package/package.json +4 -4
- package/src/api.ts +39 -19
- package/src/apis/postApi.ts +4 -0
- package/src/apis/tweetApi.ts +4 -4
- package/src/apis/userListApi.ts +2 -2
- package/test/api/postApi.test.ts +1 -1
- package/test/init.ts +5 -5
package/src/api.ts
CHANGED
|
@@ -14,38 +14,58 @@ import * as i from 'twitter-openapi-typescript-generated';
|
|
|
14
14
|
import { UsersApiUtils } from './apis/usersApi';
|
|
15
15
|
|
|
16
16
|
export class TwitterOpenApi {
|
|
17
|
-
static hash = '
|
|
17
|
+
static hash = 'a18a24e4fd96967314c452a6ec2fe6e54f112351';
|
|
18
18
|
static url = `https://raw.githubusercontent.com/fa0311/twitter-openapi/${this.hash}/src/config/placeholder.json`;
|
|
19
|
-
static header =
|
|
20
|
-
static twitter = 'https://
|
|
19
|
+
static header = 'https://raw.githubusercontent.com/fa0311/latest-user-agent/main/output.json';
|
|
20
|
+
static twitter = 'https://x.com/home';
|
|
21
21
|
static bearer =
|
|
22
22
|
'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA';
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
async get_browser_headers(): Promise<{ [key: string]: string }> {
|
|
24
|
+
async get_headers(): Promise<{ api: { [key: string]: string }; browser: { [key: string]: string } }> {
|
|
26
25
|
const raw = await TwitterOpenApi.fetchApi(TwitterOpenApi.header);
|
|
27
26
|
const json = await raw.json();
|
|
28
27
|
|
|
29
|
-
const ignore = ["host", "connection"];
|
|
30
|
-
const keys = Object.keys(json["chrome-fetch"]).filter((key) => !ignore.includes(key));
|
|
31
|
-
|
|
32
|
-
|
|
33
28
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
api: {
|
|
30
|
+
accept: '*/*',
|
|
31
|
+
'accept-encoding': 'identity',
|
|
32
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
33
|
+
'cache-control': 'no-cache',
|
|
34
|
+
pragma: 'no-cache',
|
|
35
|
+
'sec-ch-ua': '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
|
|
36
|
+
'sec-ch-ua-mobile': '?0',
|
|
37
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
38
|
+
'sec-fetch-dest': 'empty',
|
|
39
|
+
'sec-fetch-mode': 'cors',
|
|
40
|
+
'sec-fetch-site': 'same-site',
|
|
41
|
+
'client-language': 'en',
|
|
42
|
+
'active-user': 'yes',
|
|
43
|
+
'user-agent': json['chrome-fetch'],
|
|
44
|
+
},
|
|
45
|
+
browser: {
|
|
46
|
+
accept: 'text/plain, */*; q=0.01',
|
|
47
|
+
'accept-encoding': 'gzip, deflate, br',
|
|
48
|
+
'accept-language': 'en-US,en;q=0.9',
|
|
49
|
+
'cache-control': 'no-cache',
|
|
50
|
+
pragma: 'no-cache',
|
|
51
|
+
'sec-ch-ua': '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
|
|
52
|
+
'sec-ch-ua-mobile': '?0',
|
|
53
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
54
|
+
'sec-fetch-dest': 'empty',
|
|
55
|
+
'sec-fetch-mode': 'cors',
|
|
56
|
+
'sec-fetch-site': 'same-site',
|
|
57
|
+
'user-agent': json['chrome'],
|
|
58
|
+
},
|
|
59
|
+
};
|
|
39
60
|
}
|
|
40
61
|
|
|
41
|
-
|
|
42
62
|
async get_api_key(): Promise<{ [key: string]: string }> {
|
|
43
|
-
const data = await this.
|
|
63
|
+
const data = await this.get_headers();
|
|
44
64
|
return {
|
|
45
|
-
...data,
|
|
65
|
+
...data.api,
|
|
46
66
|
'x-twitter-client-language': 'en',
|
|
47
67
|
'x-twitter-active-user': 'yes',
|
|
48
|
-
authorization: `Bearer ${TwitterOpenApi.bearer}
|
|
68
|
+
authorization: `Bearer ${TwitterOpenApi.bearer}`,
|
|
49
69
|
};
|
|
50
70
|
}
|
|
51
71
|
|
|
@@ -112,7 +132,7 @@ export class TwitterOpenApi {
|
|
|
112
132
|
|
|
113
133
|
if (!cookies['gt']) {
|
|
114
134
|
const activate_headers = await this.get_api_key();
|
|
115
|
-
const { guest_token } = await TwitterOpenApi.fetchApi('https://api.
|
|
135
|
+
const { guest_token } = await TwitterOpenApi.fetchApi('https://api.x.com/1.1/guest/activate.json', {
|
|
116
136
|
method: 'POST',
|
|
117
137
|
headers: activate_headers,
|
|
118
138
|
...this.initOverrides,
|
package/src/apis/postApi.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DefaultFlag, TwitterApiUtilsResponse, initOverrides } from '@/models';
|
|
2
2
|
import { buildHeader, errorCheck } from '@/utils';
|
|
3
3
|
import * as i from 'twitter-openapi-typescript-generated';
|
|
4
|
+
import { PostCreateTweetRequestVariablesToJSON } from 'twitter-openapi-typescript-generated';
|
|
4
5
|
|
|
5
6
|
type PostCreateTweetParam = {
|
|
6
7
|
tweetText: string;
|
|
@@ -67,6 +68,8 @@ export class PostApiUtils {
|
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
variables.disallowedReplyOptions = null as any;
|
|
72
|
+
|
|
70
73
|
const response = await this.api.postCreateTweetRaw({
|
|
71
74
|
pathQueryId: this.flag[queryId]['queryId'],
|
|
72
75
|
postCreateTweetRequest: {
|
|
@@ -75,6 +78,7 @@ export class PostApiUtils {
|
|
|
75
78
|
variables: { ...variables, ...args },
|
|
76
79
|
},
|
|
77
80
|
});
|
|
81
|
+
const a = PostCreateTweetRequestVariablesToJSON(variables);
|
|
78
82
|
|
|
79
83
|
return {
|
|
80
84
|
raw: { response: response.raw },
|
package/src/apis/tweetApi.ts
CHANGED
|
@@ -214,7 +214,7 @@ export class TweetApiUtils {
|
|
|
214
214
|
|
|
215
215
|
const response = await this.request({
|
|
216
216
|
apiFn: this.api.getUserTweetsRaw,
|
|
217
|
-
convertFn: (e) => e.data.user.result.timelineV2.timeline
|
|
217
|
+
convertFn: (e) => e.data.user.result.timelineV2.timeline!.instructions,
|
|
218
218
|
key: 'UserTweets',
|
|
219
219
|
param: args,
|
|
220
220
|
});
|
|
@@ -231,7 +231,7 @@ export class TweetApiUtils {
|
|
|
231
231
|
|
|
232
232
|
const response = await this.request({
|
|
233
233
|
apiFn: this.api.getUserTweetsAndRepliesRaw,
|
|
234
|
-
convertFn: (e) => e.data.user.result.timelineV2.timeline
|
|
234
|
+
convertFn: (e) => e.data.user.result.timelineV2.timeline!.instructions,
|
|
235
235
|
key: 'UserTweetsAndReplies',
|
|
236
236
|
param: args,
|
|
237
237
|
});
|
|
@@ -248,7 +248,7 @@ export class TweetApiUtils {
|
|
|
248
248
|
|
|
249
249
|
const response = await this.request({
|
|
250
250
|
apiFn: this.api.getUserMediaRaw,
|
|
251
|
-
convertFn: (e) => e.data.user.result.timelineV2.timeline
|
|
251
|
+
convertFn: (e) => e.data.user.result.timelineV2.timeline!.instructions,
|
|
252
252
|
key: 'UserMedia',
|
|
253
253
|
param: args,
|
|
254
254
|
});
|
|
@@ -264,7 +264,7 @@ export class TweetApiUtils {
|
|
|
264
264
|
|
|
265
265
|
const response = await this.request({
|
|
266
266
|
apiFn: this.api.getLikesRaw,
|
|
267
|
-
convertFn: (e) => e.data.user.result.timelineV2.timeline
|
|
267
|
+
convertFn: (e) => e.data.user.result.timelineV2.timeline!.instructions,
|
|
268
268
|
key: 'Likes',
|
|
269
269
|
param: args,
|
|
270
270
|
});
|
package/src/apis/userListApi.ts
CHANGED
|
@@ -147,7 +147,7 @@ export class UserListApiUtils {
|
|
|
147
147
|
};
|
|
148
148
|
const response = await this.request({
|
|
149
149
|
apiFn: this.api.getFavoritersRaw,
|
|
150
|
-
convertFn: (e) => e.data.favoritersTimeline.timeline
|
|
150
|
+
convertFn: (e) => e.data.favoritersTimeline.timeline!.instructions,
|
|
151
151
|
key: 'Favoriters',
|
|
152
152
|
param: args,
|
|
153
153
|
});
|
|
@@ -163,7 +163,7 @@ export class UserListApiUtils {
|
|
|
163
163
|
};
|
|
164
164
|
const response = await this.request({
|
|
165
165
|
apiFn: this.api.getRetweetersRaw,
|
|
166
|
-
convertFn: (e) => e.data.retweetersTimeline.timeline
|
|
166
|
+
convertFn: (e) => e.data.retweetersTimeline.timeline!.instructions,
|
|
167
167
|
key: 'Retweeters',
|
|
168
168
|
param: args,
|
|
169
169
|
});
|
package/test/api/postApi.test.ts
CHANGED
|
@@ -14,7 +14,7 @@ test('postCreateReplyTweet', async () => {
|
|
|
14
14
|
const time = new Date().toISOString();
|
|
15
15
|
const response = await client.getPostApi().postCreateTweet({
|
|
16
16
|
tweetText: `Test[${time}]`,
|
|
17
|
-
inReplyToTweetId: '
|
|
17
|
+
inReplyToTweetId: '1788174612037320809',
|
|
18
18
|
});
|
|
19
19
|
expect(response.raw.response.ok).toBe(true);
|
|
20
20
|
});
|
package/test/init.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { TwitterOpenApi } from '@/api';
|
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
3
|
import * as log4js from 'log4js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
5
|
export const logger = log4js
|
|
8
6
|
.configure({
|
|
9
7
|
appenders: {
|
|
@@ -31,9 +29,11 @@ export type Cookie = {
|
|
|
31
29
|
export const getClient = async () => {
|
|
32
30
|
const api = new TwitterOpenApi();
|
|
33
31
|
const data = await fs.readFile('cookies.json', 'utf-8');
|
|
34
|
-
const parsed = JSON.parse(data)
|
|
35
|
-
const cookies = parsed as Cookie[]
|
|
36
|
-
const json = Object.fromEntries(
|
|
32
|
+
const parsed = JSON.parse(data);
|
|
33
|
+
const cookies = parsed as Cookie[];
|
|
34
|
+
const json = Object.fromEntries(
|
|
35
|
+
cookies.filter((e) => ['.twitter.com', '.x.com'].includes(e.domain)).map((e) => [e.name, e.value]),
|
|
36
|
+
);
|
|
37
37
|
const client = await api.getClientFromCookies(json);
|
|
38
38
|
return client;
|
|
39
39
|
};
|