[twitter] use GraphQL search by default (#4264)

This commit is contained in:
Mike Fährmann
2023-07-04 17:55:22 +02:00
parent 1d4db83d49
commit f86fdf64a6
2 changed files with 8 additions and 9 deletions

View File

@@ -3221,13 +3221,12 @@ extractor.twitter.search-endpoint
Type Type
``string`` ``string``
Default Default
``"auto"`` ``"graphql"``
Description Description
Selects the API endpoint used to retrieve search results. Selects the API endpoint used to retrieve search results.
* ``"rest"``: Legacy REST endpoint - returns a ``403 Forbidden`` error when not logged in * ``"graphql"``: GraphQL endpoint
* ``"graphql"``: New GraphQL endpoint * ``"rest"``: Legacy REST endpoint
* ``"auto"``: ``"rest"`` when logged in, ``"graphql"`` otherwise
extractor.twitter.timeline.strategy extractor.twitter.timeline.strategy

View File

@@ -510,13 +510,13 @@ class TwitterTimelineExtractor(TwitterExtractor):
if not self.textonly: if not self.textonly:
# try to search for media-only tweets # try to search for media-only tweets
tweet = None tweet = None
for tweet in self.api.search_adaptive(query + " filter:links"): for tweet in self.api.search_timeline(query + " filter:links"):
yield tweet yield tweet
if tweet is not None: if tweet is not None:
return return
# yield unfiltered search results # yield unfiltered search results
yield from self.api.search_adaptive(query) yield from self.api.search_timeline(query)
def _select_tweet_source(self): def _select_tweet_source(self):
strategy = self.config("strategy") strategy = self.config("strategy")
@@ -693,7 +693,7 @@ class TwitterSearchExtractor(TwitterExtractor):
except KeyError: except KeyError:
pass pass
return self.api.search_adaptive(query) return self.api.search_timeline(query)
class TwitterHashtagExtractor(TwitterExtractor): class TwitterHashtagExtractor(TwitterExtractor):
@@ -1087,8 +1087,8 @@ class TwitterAPI():
auth_token = cookies.get("auth_token", domain=cookiedomain) auth_token = cookies.get("auth_token", domain=cookiedomain)
search = extractor.config("search-endpoint") search = extractor.config("search-endpoint")
if search == "graphql" or not auth_token and search in ("auto", None): if search == "rest":
self.search_adaptive = self.search_timeline self.search_timeline = self.search_adaptive
self.headers = { self.headers = {
"Accept": "*/*", "Accept": "*/*",