Skip to content

Commit 360d3a6

Browse files
committed
feat(bookmarks): ✨ Add apis for bookmarks
1 parent 1e0929f commit 360d3a6

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

pytwitter/api.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,97 @@ def unlike_tweet(self, user_id: str, tweet_id: str) -> dict:
11941194
data = self._parse_response(resp=resp)
11951195
return data
11961196

1197+
def get_bookmark_tweets(
1198+
self,
1199+
user_id: str,
1200+
*,
1201+
pagination_token: Optional[str] = None,
1202+
max_results: Optional[int] = None,
1203+
tweet_fields: Optional[Union[str, List, Tuple]] = None,
1204+
expansions: Optional[Union[str, List, Tuple]] = None,
1205+
user_fields: Optional[Union[str, List, Tuple]] = None,
1206+
media_fields: Optional[Union[str, List, Tuple]] = None,
1207+
place_fields: Optional[Union[str, List, Tuple]] = None,
1208+
poll_fields: Optional[Union[str, List, Tuple]] = None,
1209+
return_json: bool = False,
1210+
) -> Union[dict, md.Response]:
1211+
"""
1212+
Allows you to get information about an authenticated user’s 800 most recent bookmarked Tweets.
1213+
1214+
:param user_id: The user ID whose bookmark tweets you would like to retrieve.
1215+
:param expansions: Fields for the expansions.
1216+
:param pagination_token: Token for the pagination.
1217+
:param max_results: The maximum number of results to be returned per page. Number between 1 and the 1000.
1218+
By default, each page will return 100 results.
1219+
:param tweet_fields: Fields for the tweet object.
1220+
:param user_fields: Fields for the user object, Expansion required.
1221+
:param media_fields: Fields for the media object, Expansion required.
1222+
:param place_fields: Fields for the place object, Expansion required.
1223+
:param poll_fields: Fields for the poll object, Expansion required.
1224+
:param return_json: Type for returned data. If you set True JSON data will be returned.
1225+
:return:
1226+
- data: data for the tweets.
1227+
- includes: expansions data.
1228+
- meta: pagination details
1229+
"""
1230+
args = {
1231+
"expansions": enf_comma_separated(name="expansions", value=expansions),
1232+
"tweet.fields": enf_comma_separated(
1233+
name="tweet_fields", value=tweet_fields
1234+
),
1235+
"user.fields": enf_comma_separated(name="user_fields", value=user_fields),
1236+
"media.fields": enf_comma_separated(
1237+
name="media_fields", value=media_fields
1238+
),
1239+
"place.fields": enf_comma_separated(
1240+
name="place_fields", value=place_fields
1241+
),
1242+
"poll.fields": enf_comma_separated(name="poll_fields", value=poll_fields),
1243+
"max_results": max_results,
1244+
"pagination_token": pagination_token,
1245+
}
1246+
return self._get(
1247+
url=f"{self.BASE_URL_V2}/users/{user_id}/bookmarks",
1248+
params=args,
1249+
cls=md.Tweet,
1250+
multi=True,
1251+
return_json=return_json,
1252+
)
1253+
1254+
def bookmark_tweet(self, user_id, tweet_id: str) -> dict:
1255+
"""
1256+
Causes the user ID of an authenticated user identified in the path parameter to Bookmark the target Tweet provided in the request body.
1257+
1258+
:param user_id: The user ID who you are liking a Tweet on behalf of.
1259+
It must match your user ID which authorize with the access token.
1260+
:param tweet_id: The ID of the Tweet that you would to bookmark.
1261+
:return: bookmark status data
1262+
"""
1263+
resp = self._request(
1264+
url=f"{self.BASE_URL_V2}/users/{user_id}/bookmarks",
1265+
verb="POST",
1266+
json={"tweet_id": tweet_id},
1267+
)
1268+
data = self._parse_response(resp=resp)
1269+
return data
1270+
1271+
def bookmark_tweet_remove(self, user_id, tweet_id: str) -> dict:
1272+
"""
1273+
Allows a user or authenticated user ID to remove a Bookmark of a Tweet.
1274+
1275+
:param user_id: The user ID who you are removing a Like of a Tweet on behalf of.
1276+
It must match your user ID which authorize with the access token.
1277+
:param tweet_id: The ID of the Tweet that you would remove bookmark.
1278+
:return: bookmark status data
1279+
"""
1280+
1281+
resp = self._request(
1282+
url=f"{self.BASE_URL_V2}/users/{user_id}/bookmarks/{tweet_id}",
1283+
verb="DELETE",
1284+
)
1285+
data = self._parse_response(resp=resp)
1286+
return data
1287+
11971288
def hidden_reply(self, tweet_id: str, hidden: Optional[bool] = True) -> dict:
11981289
"""
11991290
Hide or un-hide a reply to a Tweet.

0 commit comments

Comments
 (0)