[twitter] add 'tweet-endpoint' option (#4307)
use the newer TweetResultByRestId only for guests by default
This commit is contained in:
@@ -3138,6 +3138,20 @@ Description
|
||||
Transform Tweet and User metadata into a simpler, uniform format.
|
||||
|
||||
|
||||
extractor.twitter.tweet-endpoint
|
||||
--------------------------------
|
||||
Type
|
||||
``string``
|
||||
Default
|
||||
``"auto"``
|
||||
Description
|
||||
Selects the API endpoint used to retrieve single Tweets.
|
||||
|
||||
* ``"restid"``: ``/TweetResultByRestId`` - accessible to guest users
|
||||
* ``"detail"``: ``/TweetDetail`` - more stable
|
||||
* ``"auto"``: ``"detail"`` when logged in, ``"restid"`` otherwise
|
||||
|
||||
|
||||
extractor.twitter.size
|
||||
----------------------
|
||||
Type
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user