@pipedream/twitter 0.3.11 → 1.1.0
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/README.md +18 -71
- package/dist/actions/add-user-to-list/add-user-to-list.d.ts +194 -0
- package/dist/actions/add-user-to-list/add-user-to-list.mjs +44 -0
- package/dist/actions/create-tweet/create-tweet.d.ts +101 -0
- package/dist/actions/create-tweet/create-tweet.mjs +78 -0
- package/dist/actions/delete-tweet/delete-tweet.d.ts +128 -0
- package/dist/actions/delete-tweet/delete-tweet.mjs +29 -0
- package/dist/actions/follow-user/follow-user.d.ts +131 -0
- package/dist/actions/follow-user/follow-user.mjs +37 -0
- package/dist/actions/get-tweet/get-tweet.d.ts +132 -0
- package/dist/actions/get-tweet/get-tweet.mjs +34 -0
- package/dist/actions/get-user/get-user.d.ts +133 -0
- package/dist/actions/get-user/get-user.mjs +40 -0
- package/dist/actions/like-tweet/like-tweet.d.ts +128 -0
- package/dist/actions/like-tweet/like-tweet.mjs +31 -0
- package/dist/actions/list-favorites/list-favorites.d.ts +202 -0
- package/dist/actions/list-favorites/list-favorites.mjs +50 -0
- package/dist/actions/list-followers/list-followers.d.ts +202 -0
- package/dist/actions/list-followers/list-followers.mjs +50 -0
- package/dist/actions/list-lists/list-lists.d.ts +200 -0
- package/dist/actions/list-lists/list-lists.mjs +50 -0
- package/dist/actions/list-mentions/list-mentions.d.ts +200 -0
- package/dist/actions/list-mentions/list-mentions.mjs +50 -0
- package/dist/actions/list-user-tweets/list-user-tweets.d.ts +202 -0
- package/dist/actions/list-user-tweets/list-user-tweets.mjs +50 -0
- package/dist/actions/retweet/retweet.d.ts +128 -0
- package/dist/actions/retweet/retweet.mjs +34 -0
- package/dist/actions/simple-search/simple-search.d.ts +201 -0
- package/dist/actions/simple-search/simple-search.mjs +50 -0
- package/dist/actions/simple-search-in-list/simple-search-in-list.d.ts +206 -0
- package/dist/actions/simple-search-in-list/simple-search-in-list.mjs +58 -0
- package/dist/actions/unfollow-user/unfollow-user.d.ts +131 -0
- package/dist/actions/unfollow-user/unfollow-user.mjs +33 -0
- package/dist/actions/unlike-tweet/unlike-tweet.d.ts +128 -0
- package/dist/actions/unlike-tweet/unlike-tweet.mjs +29 -0
- package/dist/app/twitter.app.d.ts +65 -0
- package/dist/app/twitter.app.mjs +291 -0
- package/dist/common/additionalProps.d.ts +0 -0
- package/dist/common/additionalProps.mjs +138 -0
- package/dist/common/dataFields.d.ts +6 -0
- package/dist/common/dataFields.mjs +80 -0
- package/dist/common/expansions.d.ts +3 -0
- package/dist/common/expansions.mjs +17 -0
- package/dist/common/methods.d.ts +20 -0
- package/dist/common/methods.mjs +69 -0
- package/dist/common/types/fields.d.ts +18 -0
- package/dist/common/types/fields.mjs +1 -0
- package/dist/common/types/requestParams.d.ts +105 -0
- package/dist/common/types/requestParams.mjs +1 -0
- package/dist/common/types/responseSchemas.d.ts +42 -0
- package/dist/common/types/responseSchemas.mjs +1 -0
- package/dist/sources/common/base.d.ts +87 -0
- package/dist/sources/common/base.mjs +60 -0
- package/dist/sources/common/cacheUserId.d.ts +7 -0
- package/dist/sources/common/cacheUserId.mjs +18 -0
- package/dist/sources/common/getItemSummary.d.ts +4 -0
- package/dist/sources/common/getItemSummary.mjs +12 -0
- package/dist/sources/new-follower-of-user/new-follower-of-user.d.ts +149 -0
- package/dist/sources/new-follower-of-user/new-follower-of-user.mjs +45 -0
- package/dist/sources/new-list-followed/new-list-followed.d.ts +149 -0
- package/dist/sources/new-list-followed/new-list-followed.mjs +46 -0
- package/dist/sources/new-tweet-in-list/new-tweet-in-list.d.ts +147 -0
- package/dist/sources/new-tweet-in-list/new-tweet-in-list.mjs +42 -0
- package/dist/sources/new-tweet-liked-by-user/new-tweet-liked-by-user.d.ts +149 -0
- package/dist/sources/new-tweet-liked-by-user/new-tweet-liked-by-user.mjs +45 -0
- package/dist/sources/new-tweet-posted-by-user/new-tweet-posted-by-user.d.ts +149 -0
- package/dist/sources/new-tweet-posted-by-user/new-tweet-posted-by-user.mjs +45 -0
- package/dist/sources/new-tweet-posted-matching-query/new-tweet-posted-matching-query.d.ts +147 -0
- package/dist/sources/new-tweet-posted-matching-query/new-tweet-posted-matching-query.mjs +44 -0
- package/dist/sources/new-unfollower-of-user/new-unfollower-of-user.d.ts +149 -0
- package/dist/sources/new-unfollower-of-user/new-unfollower-of-user.mjs +75 -0
- package/dist/sources/new-user-followed/new-user-followed.d.ts +148 -0
- package/dist/sources/new-user-followed/new-user-followed.mjs +46 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +10 -14
- package/actions/add-user-to-list/add-user-to-list.mjs +0 -62
- package/actions/advanced-search/advanced-search.mjs +0 -113
- package/actions/common.mjs +0 -29
- package/actions/create-tweet/create-tweet.mjs +0 -146
- package/actions/delete-tweet/delete-tweet.mjs +0 -42
- package/actions/follow-user/follow-user.mjs +0 -48
- package/actions/get-tweet/get-tweet.mjs +0 -42
- package/actions/get-user/get-user.mjs +0 -50
- package/actions/like-tweet/like-tweet.mjs +0 -42
- package/actions/list-favorites/list-favorites.mjs +0 -63
- package/actions/list-followers/list-followers.mjs +0 -67
- package/actions/list-lists/list-lists.mjs +0 -69
- package/actions/list-mentions/list-mentions.mjs +0 -55
- package/actions/list-pending-followers/list-pending-followers.mjs +0 -32
- package/actions/list-retweets/list-retweets.mjs +0 -54
- package/actions/list-user-tweets/list-user-tweets.mjs +0 -80
- package/actions/retweet/retweet.mjs +0 -27
- package/actions/simple-search/simple-search.mjs +0 -62
- package/actions/simple-search-in-list/simple-search-in-list.mjs +0 -48
- package/actions/unfollow-user/unfollow-user.mjs +0 -48
- package/actions/unlike-tweet/unlike-tweet.mjs +0 -40
- package/actions/upload-media/upload-media.mjs +0 -122
- package/old.md +0 -169
- package/sources/common/followed.mjs +0 -38
- package/sources/common/followers.mjs +0 -159
- package/sources/common/tweets.mjs +0 -155
- package/sources/language-codes.mjs +0 -742
- package/sources/my-liked-tweets/my-liked-tweets.mjs +0 -30
- package/sources/my-tweets/my-tweets.mjs +0 -48
- package/sources/new-follower-of-me/new-follower-of-me.mjs +0 -69
- package/sources/new-follower-of-user/new-follower-of-user.mjs +0 -25
- package/sources/new-list-followed/new-list-followed.mjs +0 -24
- package/sources/new-trends-by-geo/new-trends-by-geo.mjs +0 -40
- package/sources/new-tweet-in-list/new-tweet-in-list.mjs +0 -49
- package/sources/new-unfollower-of-me/new-unfollower-of-me.mjs +0 -16
- package/sources/new-unfollower-of-user/new-unfollower-of-user.mjs +0 -25
- package/sources/new-user-followed/new-user-followed.mjs +0 -25
- package/sources/search-mentions/search-mentions.mjs +0 -144
- package/sources/tweets-liked-by-user/tweets-liked-by-user.mjs +0 -38
- package/sources/user-tweets/user-tweets.mjs +0 -49
- package/sources/watch-retweets-of-me/watch-retweets-of-me.mjs +0 -36
- package/sources/watch-retweets-of-my-tweet/watch-retweets-of-my-tweet.mjs +0 -44
- package/sources/watch-retweets-of-user-tweet/watch-retweets-of-user-tweet.mjs +0 -34
- package/twitter.app.mjs +0 -1161
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import OAuth from "oauth-1.0a";
|
|
2
|
+
import { AddUserToListParams, CreateTweetParams, DeleteTweetParams, FollowUserParams, GetUserLikedTweetParams, GetUserOwnedListsParams, GetTweetParams, GetUserFollowedListsParams, GetUserMentionsParams, GetUserParams, GetUserTweetsParams, HttpRequestParams, LikeTweetParams, GetUserFollowersParams, GetUserFollowingParams, PaginatedRequestParams, RetweetParams, SearchTweetsParams, UnfollowUserParams, UnlikeTweetParams, GetListTweetsParams, GetAuthenticatedUserParams } from "../common/types/requestParams.js";
|
|
3
|
+
import { List, PaginatedResponseObject, ResponseObject, Tweet, TwitterEntity, User } from "../common/types/responseSchemas.js";
|
|
4
|
+
declare const _default: import("@pipedream/types").App<{
|
|
5
|
+
_getAuthHeader(config: HttpRequestParams): Promise<OAuth.Header>;
|
|
6
|
+
_getBaseUrl(): "https://api.twitter.com/2";
|
|
7
|
+
_httpRequest({ $, ...args }: HttpRequestParams): Promise<ResponseObject<TwitterEntity>>;
|
|
8
|
+
_paginatedRequest({ maxResults, maxPerPage, params, ...args }: PaginatedRequestParams): Promise<PaginatedResponseObject<TwitterEntity>>;
|
|
9
|
+
addUserToList({ listId, ...args }: AddUserToListParams): Promise<object>;
|
|
10
|
+
createTweet(args: CreateTweetParams): Promise<object>;
|
|
11
|
+
deleteTweet({ tweetId, ...args }: DeleteTweetParams): Promise<object>;
|
|
12
|
+
followUser(args: FollowUserParams): Promise<object>;
|
|
13
|
+
getListTweets({ listId, ...args }: GetListTweetsParams): Promise<PaginatedResponseObject<Tweet>>;
|
|
14
|
+
getTweet({ tweetId, ...args }: GetTweetParams): Promise<ResponseObject<Tweet>>;
|
|
15
|
+
getAuthenticatedUser(args: GetAuthenticatedUserParams): Promise<ResponseObject<User>>;
|
|
16
|
+
getAuthenticatedUserId(): Promise<User["id"]>;
|
|
17
|
+
getUserLikedTweets({ userId, ...args }: GetUserLikedTweetParams): Promise<PaginatedResponseObject<Tweet>>;
|
|
18
|
+
getUserOwnedLists({ userId, ...args }: GetUserOwnedListsParams): Promise<PaginatedResponseObject<List>>;
|
|
19
|
+
getUserFollowedLists({ userId, ...args }: GetUserFollowedListsParams): Promise<PaginatedResponseObject<List>>;
|
|
20
|
+
getUserMentions({ userId, ...args }: GetUserMentionsParams): Promise<PaginatedResponseObject<Tweet>>;
|
|
21
|
+
getUserTweets({ userId, ...args }: GetUserTweetsParams): Promise<PaginatedResponseObject<Tweet>>;
|
|
22
|
+
getUserByUsername(username: string): Promise<ResponseObject<User>>;
|
|
23
|
+
getUser({ userId, ...args }: GetUserParams): Promise<ResponseObject<User>>;
|
|
24
|
+
likeTweet(args: LikeTweetParams): Promise<object>;
|
|
25
|
+
getUserFollowers({ userId, ...args }: GetUserFollowersParams): Promise<PaginatedResponseObject<User>>;
|
|
26
|
+
getUserFollowing({ userId, ...args }: GetUserFollowingParams): Promise<PaginatedResponseObject<User>>;
|
|
27
|
+
retweet(args: RetweetParams): Promise<object>;
|
|
28
|
+
searchTweets(args: SearchTweetsParams): Promise<PaginatedResponseObject<Tweet>>;
|
|
29
|
+
unfollowUser({ userId, ...args }: UnfollowUserParams): Promise<object>;
|
|
30
|
+
unlikeTweet({ tweetId, ...args }: UnlikeTweetParams): Promise<object>;
|
|
31
|
+
}, {
|
|
32
|
+
maxResults: {
|
|
33
|
+
type: string;
|
|
34
|
+
label: string;
|
|
35
|
+
description: string;
|
|
36
|
+
optional: boolean;
|
|
37
|
+
};
|
|
38
|
+
listId: {
|
|
39
|
+
type: string;
|
|
40
|
+
label: string;
|
|
41
|
+
description: string;
|
|
42
|
+
options(): Promise<{
|
|
43
|
+
label: string;
|
|
44
|
+
value: string;
|
|
45
|
+
}[]>;
|
|
46
|
+
};
|
|
47
|
+
userNameOrId: {
|
|
48
|
+
type: string;
|
|
49
|
+
label: string;
|
|
50
|
+
description: string;
|
|
51
|
+
optional: boolean;
|
|
52
|
+
default: string;
|
|
53
|
+
};
|
|
54
|
+
tweetId: {
|
|
55
|
+
type: string;
|
|
56
|
+
label: string;
|
|
57
|
+
description: string;
|
|
58
|
+
};
|
|
59
|
+
query: {
|
|
60
|
+
type: string;
|
|
61
|
+
label: string;
|
|
62
|
+
description: string;
|
|
63
|
+
};
|
|
64
|
+
}>;
|
|
65
|
+
export default _default;
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import OAuth from "oauth-1.0a";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
import { defineApp } from "@pipedream/types";
|
|
4
|
+
import { axios } from "@pipedream/platform";
|
|
5
|
+
export default defineApp({
|
|
6
|
+
type: "app",
|
|
7
|
+
app: "twitter",
|
|
8
|
+
propDefinitions: {
|
|
9
|
+
maxResults: {
|
|
10
|
+
type: "integer",
|
|
11
|
+
label: "Max Results",
|
|
12
|
+
description: "Maximum total amount of items to return. The maximum amount of requests that can be made is 5.",
|
|
13
|
+
optional: true,
|
|
14
|
+
},
|
|
15
|
+
listId: {
|
|
16
|
+
type: "string",
|
|
17
|
+
label: "List ID",
|
|
18
|
+
description: "Select a **List** owned by the authenticated user, or use a custom *List ID*.",
|
|
19
|
+
async options() {
|
|
20
|
+
const userId = await this.getAuthenticatedUserId();
|
|
21
|
+
const lists = await this.getUserOwnedLists({
|
|
22
|
+
userId,
|
|
23
|
+
});
|
|
24
|
+
return (lists.data?.map(({ id, name, }) => ({
|
|
25
|
+
label: name,
|
|
26
|
+
value: id,
|
|
27
|
+
})) ?? []);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
userNameOrId: {
|
|
31
|
+
type: "string",
|
|
32
|
+
label: "User Name or ID",
|
|
33
|
+
description: "A Twitter username (handle) prefixed with `@` (e.g. `@pipedream`). You can also use the string `me` to use the authenticated user (default), or a numeric User ID.",
|
|
34
|
+
optional: true,
|
|
35
|
+
default: "me",
|
|
36
|
+
},
|
|
37
|
+
// See comment on "../common/additionalProps.ts"
|
|
38
|
+
/*
|
|
39
|
+
includeAllFields: {
|
|
40
|
+
type: "boolean",
|
|
41
|
+
label: "Include All Metadata",
|
|
42
|
+
description: "If set to `false`, you can choose which fields will be returned for each data type.",
|
|
43
|
+
optional: true,
|
|
44
|
+
default: true,
|
|
45
|
+
reloadProps: true,
|
|
46
|
+
},
|
|
47
|
+
*/
|
|
48
|
+
tweetId: {
|
|
49
|
+
type: "string",
|
|
50
|
+
label: "Tweet ID",
|
|
51
|
+
description: "The numerical ID of the tweet.",
|
|
52
|
+
},
|
|
53
|
+
query: {
|
|
54
|
+
type: "string",
|
|
55
|
+
label: "Query",
|
|
56
|
+
description: "One query for matching Tweets. See the [Twitter API guide on building queries](https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query).",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
methods: {
|
|
60
|
+
async _getAuthHeader(config) {
|
|
61
|
+
const { oauth_access_token: key, oauth_refresh_token: secret, } = this.$auth;
|
|
62
|
+
const consumer = {
|
|
63
|
+
key,
|
|
64
|
+
secret,
|
|
65
|
+
};
|
|
66
|
+
const oauth = new OAuth({
|
|
67
|
+
consumer,
|
|
68
|
+
signature_method: "HMAC-SHA1",
|
|
69
|
+
hash_function(base_string, key) {
|
|
70
|
+
return crypto
|
|
71
|
+
.createHmac("sha1", key)
|
|
72
|
+
.update(base_string)
|
|
73
|
+
.digest("base64");
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (!config.method)
|
|
77
|
+
config.method = "GET";
|
|
78
|
+
return oauth.toHeader(oauth.authorize(config, consumer));
|
|
79
|
+
},
|
|
80
|
+
_getBaseUrl() {
|
|
81
|
+
return "https://api.twitter.com/2";
|
|
82
|
+
},
|
|
83
|
+
async _httpRequest({ $ = this, ...args }) {
|
|
84
|
+
const config = {
|
|
85
|
+
baseURL: this._getBaseUrl(),
|
|
86
|
+
...args,
|
|
87
|
+
};
|
|
88
|
+
// const headers = this._getAuthHeader(config);
|
|
89
|
+
const request = () => axios($, {
|
|
90
|
+
...config,
|
|
91
|
+
// headers,
|
|
92
|
+
}, {
|
|
93
|
+
oauthSignerUri: this.$auth.oauth_signer_uri,
|
|
94
|
+
token: {
|
|
95
|
+
key: this.$auth.oauth_access_token,
|
|
96
|
+
secret: this.$auth.oauth_refresh_token,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
let response, counter = 1;
|
|
100
|
+
do {
|
|
101
|
+
try {
|
|
102
|
+
response = await request();
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
console.log(`Request error on attempt #${counter}: `, err);
|
|
106
|
+
}
|
|
107
|
+
} while (!response && ++counter < 3);
|
|
108
|
+
if (!response)
|
|
109
|
+
response = await request();
|
|
110
|
+
return response;
|
|
111
|
+
},
|
|
112
|
+
async _paginatedRequest({ maxResults = 100, maxPerPage = 100, params, ...args }) {
|
|
113
|
+
const totalData = [], totalIncludes = {};
|
|
114
|
+
let paginationToken;
|
|
115
|
+
let resultCount = 0;
|
|
116
|
+
do {
|
|
117
|
+
const perPage = Math.min(maxResults - resultCount, maxPerPage);
|
|
118
|
+
const { data, meta: { next_token }, includes, } = await this._httpRequest({
|
|
119
|
+
params: {
|
|
120
|
+
...params,
|
|
121
|
+
max_results: perPage,
|
|
122
|
+
pagination_token: paginationToken,
|
|
123
|
+
},
|
|
124
|
+
...args,
|
|
125
|
+
});
|
|
126
|
+
if (!data)
|
|
127
|
+
break;
|
|
128
|
+
totalData.push(...(Array.isArray(data)
|
|
129
|
+
? data
|
|
130
|
+
: [
|
|
131
|
+
data,
|
|
132
|
+
]));
|
|
133
|
+
if (includes) {
|
|
134
|
+
Object.entries(includes).forEach(([key, value]) => {
|
|
135
|
+
if (!totalIncludes[key])
|
|
136
|
+
totalIncludes[key] = [];
|
|
137
|
+
totalIncludes[key].push(...value);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
paginationToken = next_token;
|
|
141
|
+
resultCount += perPage;
|
|
142
|
+
} while (paginationToken && resultCount < maxResults);
|
|
143
|
+
return {
|
|
144
|
+
data: totalData,
|
|
145
|
+
includes: totalIncludes,
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
async addUserToList({ listId, ...args }) {
|
|
149
|
+
return this._httpRequest({
|
|
150
|
+
method: "POST",
|
|
151
|
+
url: `/lists/${listId}/members`,
|
|
152
|
+
...args,
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
async createTweet(args) {
|
|
156
|
+
return this._httpRequest({
|
|
157
|
+
method: "POST",
|
|
158
|
+
url: "/tweets",
|
|
159
|
+
...args,
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
async deleteTweet({ tweetId, ...args }) {
|
|
163
|
+
return this._httpRequest({
|
|
164
|
+
method: "DELETE",
|
|
165
|
+
url: `/tweets/${tweetId}`,
|
|
166
|
+
...args,
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
async followUser(args) {
|
|
170
|
+
const id = await this.getAuthenticatedUserId();
|
|
171
|
+
return this._httpRequest({
|
|
172
|
+
method: "POST",
|
|
173
|
+
url: `/users/${id}/following`,
|
|
174
|
+
...args,
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
async getListTweets({ listId, ...args }) {
|
|
178
|
+
return this._paginatedRequest({
|
|
179
|
+
url: `/lists/${listId}/tweets`,
|
|
180
|
+
...args,
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
async getTweet({ tweetId, ...args }) {
|
|
184
|
+
return this._httpRequest({
|
|
185
|
+
url: `/tweets/${tweetId}`,
|
|
186
|
+
...args,
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
async getAuthenticatedUser(args) {
|
|
190
|
+
return this._httpRequest({
|
|
191
|
+
url: "/users/me",
|
|
192
|
+
...args,
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
async getAuthenticatedUserId() {
|
|
196
|
+
const response = await this.getAuthenticatedUser();
|
|
197
|
+
return response.data.id;
|
|
198
|
+
},
|
|
199
|
+
async getUserLikedTweets({ userId, ...args }) {
|
|
200
|
+
return this._paginatedRequest({
|
|
201
|
+
url: `/users/${userId}/liked_tweets`,
|
|
202
|
+
...args,
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
async getUserOwnedLists({ userId, ...args }) {
|
|
206
|
+
return this._httpRequest({
|
|
207
|
+
url: `/users/${userId}/owned_lists`,
|
|
208
|
+
...args,
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
async getUserFollowedLists({ userId, ...args }) {
|
|
212
|
+
return this._paginatedRequest({
|
|
213
|
+
url: `/users/${userId}/followed_lists`,
|
|
214
|
+
...args,
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
async getUserMentions({ userId, ...args }) {
|
|
218
|
+
return this._paginatedRequest({
|
|
219
|
+
url: `/users/${userId}/mentions`,
|
|
220
|
+
...args,
|
|
221
|
+
});
|
|
222
|
+
},
|
|
223
|
+
async getUserTweets({ userId, ...args }) {
|
|
224
|
+
return this._paginatedRequest({
|
|
225
|
+
url: `/users/${userId}/tweets`,
|
|
226
|
+
...args,
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
async getUserByUsername(username) {
|
|
230
|
+
return this._httpRequest({
|
|
231
|
+
url: `/users/by/username/${username}`,
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
async getUser({ userId, ...args }) {
|
|
235
|
+
return this._httpRequest({
|
|
236
|
+
url: `/users/${userId}`,
|
|
237
|
+
...args,
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
async likeTweet(args) {
|
|
241
|
+
const id = await this.getAuthenticatedUserId();
|
|
242
|
+
return this._httpRequest({
|
|
243
|
+
method: "POST",
|
|
244
|
+
url: `/users/${id}/likes`,
|
|
245
|
+
...args,
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
async getUserFollowers({ userId, ...args }) {
|
|
249
|
+
return this._paginatedRequest({
|
|
250
|
+
url: `/users/${userId}/followers`,
|
|
251
|
+
...args,
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
async getUserFollowing({ userId, ...args }) {
|
|
255
|
+
return this._paginatedRequest({
|
|
256
|
+
url: `/users/${userId}/following`,
|
|
257
|
+
...args,
|
|
258
|
+
});
|
|
259
|
+
},
|
|
260
|
+
async retweet(args) {
|
|
261
|
+
const id = await this.getAuthenticatedUserId();
|
|
262
|
+
return this._httpRequest({
|
|
263
|
+
method: "POST",
|
|
264
|
+
url: `/users/${id}/retweets`,
|
|
265
|
+
...args,
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
async searchTweets(args) {
|
|
269
|
+
return this._paginatedRequest({
|
|
270
|
+
url: "/tweets/search/recent",
|
|
271
|
+
...args,
|
|
272
|
+
});
|
|
273
|
+
},
|
|
274
|
+
async unfollowUser({ userId, ...args }) {
|
|
275
|
+
const id = await this.getAuthenticatedUserId();
|
|
276
|
+
return this._httpRequest({
|
|
277
|
+
method: "DELETE",
|
|
278
|
+
url: `/users/${id}/following/${userId}`,
|
|
279
|
+
...args,
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
async unlikeTweet({ tweetId, ...args }) {
|
|
283
|
+
const id = await this.getAuthenticatedUserId();
|
|
284
|
+
return this._httpRequest({
|
|
285
|
+
method: "DELETE",
|
|
286
|
+
url: `/users/${id}/likes/${tweetId}`,
|
|
287
|
+
...args,
|
|
288
|
+
});
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// This is no longer being used. Requests send all the available fields by default.
|
|
2
|
+
// If it ever makes sense to allow customizing which fields are sent, this can be re-enabled
|
|
3
|
+
/*
|
|
4
|
+
import {
|
|
5
|
+
LIST_FIELD_OPTIONS,
|
|
6
|
+
MEDIA_FIELD_OPTIONS,
|
|
7
|
+
PLACE_FIELD_OPTIONS,
|
|
8
|
+
POLL_FIELD_OPTIONS,
|
|
9
|
+
TWEET_FIELD_OPTIONS,
|
|
10
|
+
USER_FIELD_OPTIONS,
|
|
11
|
+
} from "./dataFields.mjs";
|
|
12
|
+
import {
|
|
13
|
+
LIST_EXPANSION_OPTIONS,
|
|
14
|
+
TWEET_EXPANSION_OPTIONS,
|
|
15
|
+
USER_EXPANSION_OPTIONS,
|
|
16
|
+
} from "./expansions.mjs";
|
|
17
|
+
|
|
18
|
+
// These cannot be propDefinitions in the app file, because additionalProps() needs them to be primitives
|
|
19
|
+
const listExpansions = {
|
|
20
|
+
type: "string[]",
|
|
21
|
+
label: "Expansions",
|
|
22
|
+
optional: true,
|
|
23
|
+
description:
|
|
24
|
+
"Additional data objects related to the List(s) to be included in the response.",
|
|
25
|
+
options: LIST_EXPANSION_OPTIONS,
|
|
26
|
+
};
|
|
27
|
+
const tweetExpansions = {
|
|
28
|
+
type: "string[]",
|
|
29
|
+
label: "Expansions",
|
|
30
|
+
optional: true,
|
|
31
|
+
description:
|
|
32
|
+
"Additional data objects related to the Tweet(s) to be included in the response.",
|
|
33
|
+
options: TWEET_EXPANSION_OPTIONS,
|
|
34
|
+
};
|
|
35
|
+
const userExpansions = {
|
|
36
|
+
type: "string[]",
|
|
37
|
+
label: "Expansions",
|
|
38
|
+
optional: true,
|
|
39
|
+
description:
|
|
40
|
+
"Additional data objects related to the User(s) to be included in the response.",
|
|
41
|
+
options: USER_EXPANSION_OPTIONS,
|
|
42
|
+
};
|
|
43
|
+
const listFields = {
|
|
44
|
+
type: "string[]",
|
|
45
|
+
label: "List Fields",
|
|
46
|
+
description:
|
|
47
|
+
"Specific [list fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/lists) to be included in the returned list object.",
|
|
48
|
+
optional: true,
|
|
49
|
+
options: LIST_FIELD_OPTIONS,
|
|
50
|
+
};
|
|
51
|
+
const mediaFields = {
|
|
52
|
+
type: "string[]",
|
|
53
|
+
label: "Media Fields",
|
|
54
|
+
description:
|
|
55
|
+
"Specific [media fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/media) to be included in the returned Tweet(s). Only applicable if the Tweet contains media and you've requested the `attachments.media_keys` expansion.",
|
|
56
|
+
optional: true,
|
|
57
|
+
options: MEDIA_FIELD_OPTIONS,
|
|
58
|
+
};
|
|
59
|
+
const placeFields = {
|
|
60
|
+
type: "string[]",
|
|
61
|
+
label: "Place Fields",
|
|
62
|
+
description:
|
|
63
|
+
"Specific [place fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/place) to be included in the returned Tweet(s). Only applicable if the Tweet contains a place and you've requested the `geo.place_id` expansion.",
|
|
64
|
+
optional: true,
|
|
65
|
+
options: PLACE_FIELD_OPTIONS,
|
|
66
|
+
};
|
|
67
|
+
const pollFields = {
|
|
68
|
+
type: "string[]",
|
|
69
|
+
label: "Poll Fields",
|
|
70
|
+
description:
|
|
71
|
+
"Specific [poll fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/poll) to be included in the returned Tweet(s). Only applicable if the Tweet contains a poll and you've requested the `attachments.poll_ids` expansion.",
|
|
72
|
+
optional: true,
|
|
73
|
+
options: POLL_FIELD_OPTIONS,
|
|
74
|
+
};
|
|
75
|
+
const tweetFields = {
|
|
76
|
+
type: "string[]",
|
|
77
|
+
label: "Tweet Fields",
|
|
78
|
+
description:
|
|
79
|
+
"Specific [tweet fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/tweet) to be included in the returned Tweet(s). If you've requested the `referenced_tweets.id` expansion, these fields will also be returned for any included referenced Tweets.",
|
|
80
|
+
optional: true,
|
|
81
|
+
options: TWEET_FIELD_OPTIONS,
|
|
82
|
+
};
|
|
83
|
+
const userFields = {
|
|
84
|
+
type: "string[]",
|
|
85
|
+
label: "User Fields",
|
|
86
|
+
description:
|
|
87
|
+
"Specific [user fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user) to be included in the returned Tweet(s). Only applicable if you've requested one of the user expansions: `author_id`, `entities.mentions.username`, `in_reply_to_user_id`, `referenced_tweets.id.author_id`.",
|
|
88
|
+
optional: true,
|
|
89
|
+
options: USER_FIELD_OPTIONS,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// The 'any' here is needed because of the additionalProps behavior
|
|
93
|
+
|
|
94
|
+
export async function listAdditionalProps(): Promise<Record<string, any>> {
|
|
95
|
+
return this.includeAllFields === false
|
|
96
|
+
? {
|
|
97
|
+
expansions: listExpansions,
|
|
98
|
+
listFields,
|
|
99
|
+
userFields: {
|
|
100
|
+
...userFields,
|
|
101
|
+
description:
|
|
102
|
+
"Specific [user fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user) to be included in the returned user object. Only applicable if you've requested the `owner_id` expansion.",
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
: {};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function tweetAdditionalProps(): Promise<Record<string, any>> {
|
|
109
|
+
return this.includeAllFields === false
|
|
110
|
+
? {
|
|
111
|
+
expansions: tweetExpansions,
|
|
112
|
+
mediaFields,
|
|
113
|
+
placeFields,
|
|
114
|
+
pollFields,
|
|
115
|
+
tweetFields,
|
|
116
|
+
userFields,
|
|
117
|
+
}
|
|
118
|
+
: {};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function userAdditionalProps(): Promise<Record<string, any>> {
|
|
122
|
+
return this.includeAllFields === false
|
|
123
|
+
? {
|
|
124
|
+
expansions: userExpansions,
|
|
125
|
+
tweetFields: {
|
|
126
|
+
...tweetFields,
|
|
127
|
+
description:
|
|
128
|
+
"Specific [tweet fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/tweet) to be included in the returned pinned Tweet. Only applicable if the user has a pinned Tweet and you've requested the `referenced_tweets.id` expansion.",
|
|
129
|
+
},
|
|
130
|
+
userFields: {
|
|
131
|
+
...userFields,
|
|
132
|
+
description:
|
|
133
|
+
"Specific [user fields](https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user) to be included in the returned user object.",
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
: {};
|
|
137
|
+
}
|
|
138
|
+
*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const LIST_FIELD_OPTIONS: string[];
|
|
2
|
+
export declare const MEDIA_FIELD_OPTIONS: string[];
|
|
3
|
+
export declare const PLACE_FIELD_OPTIONS: string[];
|
|
4
|
+
export declare const POLL_FIELD_OPTIONS: string[];
|
|
5
|
+
export declare const TWEET_FIELD_OPTIONS: string[];
|
|
6
|
+
export declare const USER_FIELD_OPTIONS: string[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export const LIST_FIELD_OPTIONS = [
|
|
2
|
+
"created_at",
|
|
3
|
+
"follower_count",
|
|
4
|
+
"member_count",
|
|
5
|
+
"private",
|
|
6
|
+
"description",
|
|
7
|
+
"owner_id",
|
|
8
|
+
];
|
|
9
|
+
export const MEDIA_FIELD_OPTIONS = [
|
|
10
|
+
"duration_ms",
|
|
11
|
+
"height",
|
|
12
|
+
"media_key",
|
|
13
|
+
"preview_image_url",
|
|
14
|
+
"type",
|
|
15
|
+
"url",
|
|
16
|
+
"width",
|
|
17
|
+
"public_metrics",
|
|
18
|
+
"non_public_metrics",
|
|
19
|
+
"organic_metrics",
|
|
20
|
+
"promoted_metrics",
|
|
21
|
+
"alt_text",
|
|
22
|
+
"variants",
|
|
23
|
+
];
|
|
24
|
+
export const PLACE_FIELD_OPTIONS = [
|
|
25
|
+
"contained_within",
|
|
26
|
+
"country",
|
|
27
|
+
"country_code",
|
|
28
|
+
"full_name",
|
|
29
|
+
"geo",
|
|
30
|
+
"id",
|
|
31
|
+
"name",
|
|
32
|
+
"place_type",
|
|
33
|
+
];
|
|
34
|
+
export const POLL_FIELD_OPTIONS = [
|
|
35
|
+
"duration_minutes",
|
|
36
|
+
"end_datetime",
|
|
37
|
+
"id",
|
|
38
|
+
"options",
|
|
39
|
+
"voting_status",
|
|
40
|
+
];
|
|
41
|
+
export const TWEET_FIELD_OPTIONS = [
|
|
42
|
+
"attachments",
|
|
43
|
+
"author_id",
|
|
44
|
+
"context_annotations",
|
|
45
|
+
"conversation_id",
|
|
46
|
+
"created_at",
|
|
47
|
+
"edit_controls",
|
|
48
|
+
"entities",
|
|
49
|
+
"geo",
|
|
50
|
+
"id",
|
|
51
|
+
"in_reply_to_user_id",
|
|
52
|
+
"lang",
|
|
53
|
+
"non_public_metrics",
|
|
54
|
+
"public_metrics",
|
|
55
|
+
"organic_metrics",
|
|
56
|
+
"promoted_metrics",
|
|
57
|
+
"possibly_sensitive",
|
|
58
|
+
"referenced_tweets",
|
|
59
|
+
"reply_settings",
|
|
60
|
+
"source",
|
|
61
|
+
"text",
|
|
62
|
+
"withheld",
|
|
63
|
+
];
|
|
64
|
+
export const USER_FIELD_OPTIONS = [
|
|
65
|
+
"created_at",
|
|
66
|
+
"description",
|
|
67
|
+
"entities",
|
|
68
|
+
"id",
|
|
69
|
+
"location",
|
|
70
|
+
"name",
|
|
71
|
+
"pinned_tweet_id",
|
|
72
|
+
"profile_image_url",
|
|
73
|
+
"protected",
|
|
74
|
+
"public_metrics",
|
|
75
|
+
"url",
|
|
76
|
+
"username",
|
|
77
|
+
"verified",
|
|
78
|
+
"verified_type",
|
|
79
|
+
"withheld",
|
|
80
|
+
];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const LIST_EXPANSION_OPTIONS = [
|
|
2
|
+
"owner_id",
|
|
3
|
+
];
|
|
4
|
+
export const TWEET_EXPANSION_OPTIONS = [
|
|
5
|
+
"attachments.poll_ids",
|
|
6
|
+
"attachments.media_keys",
|
|
7
|
+
"author_id",
|
|
8
|
+
"edit_history_tweet_ids",
|
|
9
|
+
"entities.mentions.username",
|
|
10
|
+
"geo.place_id",
|
|
11
|
+
"in_reply_to_user_id",
|
|
12
|
+
"referenced_tweets.id",
|
|
13
|
+
"referenced_tweets.id.author_id",
|
|
14
|
+
];
|
|
15
|
+
export const USER_EXPANSION_OPTIONS = [
|
|
16
|
+
"pinned_tweet_id",
|
|
17
|
+
];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function getUserId(): Promise<string>;
|
|
2
|
+
export declare function getMultiItemSummary(name: string, length: number): string;
|
|
3
|
+
export declare function getListFields(): {
|
|
4
|
+
expansions: string;
|
|
5
|
+
"list.fields": string;
|
|
6
|
+
"user.fields": string;
|
|
7
|
+
};
|
|
8
|
+
export declare function getTweetFields(): {
|
|
9
|
+
expansions: string;
|
|
10
|
+
"media.fields": string;
|
|
11
|
+
"place.fields": string;
|
|
12
|
+
"poll.fields": string;
|
|
13
|
+
"tweet.fields": string;
|
|
14
|
+
"user.fields": string;
|
|
15
|
+
};
|
|
16
|
+
export declare function getUserFields(): {
|
|
17
|
+
expansions: string;
|
|
18
|
+
"tweet.fields": string;
|
|
19
|
+
"user.fields": string;
|
|
20
|
+
};
|