[twitter] add 'tweet-endpoint' option (#4307)

use the newer TweetResultByRestId only for guests by default
This commit is contained in:
Mike Fährmann
2023-07-18 17:19:32 +02:00
parent 20ed647f6f
commit 90231f2d5a
2 changed files with 37 additions and 2 deletions

View File

@@ -952,8 +952,13 @@ Your reaction.""",
if conversations:
self._accessible = (conversations == "accessible")
return self._tweets_conversation(self.tweet_id)
else:
return self._tweets_single(self.tweet_id)
endpoint = self.config("tweet-endpoint")
if endpoint == "detail" or endpoint in (None, "auto") and \
self.api.headers["x-twitter-auth-type"]:
return self._tweets_detail(self.tweet_id)
return self._tweets_single(self.tweet_id)
def _tweets_single(self, tweet_id):
tweets = []
@@ -970,6 +975,22 @@ Your reaction.""",
return tweets
def _tweets_detail(self, tweet_id):
tweets = []
for tweet in self.api.tweet_detail(tweet_id):
if tweet["rest_id"] == tweet_id or \
tweet.get("_retweet_id_str") == tweet_id:
if self._user_obj is None:
self._assign_user(tweet["core"]["user_results"]["result"])
tweets.append(tweet)
tweet_id = tweet["legacy"].get("quoted_status_id_str")
if not tweet_id:
break
return tweets
def _tweets_conversation(self, tweet_id):
tweets = self.api.tweet_detail(tweet_id)
buffer = []