Skip to content

Commit 6c4dfbf

Browse files
committed
Fix: [Server][Utils/TwitterGraphQLAPI] ツイート検索時の API リクエストペイロードをさらに Twitter Web App の挙動に合わせる
1 parent 4c2974d commit 6c4dfbf

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

server/app/utils/TwitterGraphQLAPI.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,10 @@ async def homeLatestTimeline(
908908
# variables の挿入順序を Twitter Web App に厳密に合わせるためにこのような実装としている
909909
variables: dict[str, Any] = {}
910910
if cursor_id is None:
911-
## カーソル ID が指定されていないときは、requestContext:launch になるので20件取得する
911+
## カーソル ID が指定されていないときは20件取得する (Twitter Web App の挙動に合わせる)
912912
variables['count'] = 20
913913
else:
914-
## カーソル ID が指定されているときは、requestContext:ptr になるので40件取得する
914+
## カーソル ID が指定されているときは40件取得する (Twitter Web App の挙動に合わせる)
915915
variables['count'] = 40
916916
if cursor_id is not None:
917917
variables['cursor'] = cursor_id
@@ -977,7 +977,6 @@ async def searchTimeline(
977977
search_type: Literal['Top', 'Latest'],
978978
query: str,
979979
cursor_id: str | None = None,
980-
count: int = 20,
981980
) -> schemas.TimelineTweetsResult | schemas.TwitterAPIResult:
982981
"""
983982
ツイートを検索する
@@ -986,7 +985,6 @@ async def searchTimeline(
986985
search_type (Literal['Top', 'Latest']): 検索タイプ (Top: トップツイート, Latest: 最新ツイート)
987986
query (str): 検索クエリ
988987
cursor_id (str | None, optional): 次のページを取得するためのカーソル ID (デフォルトは None)
989-
count (int, optional): 取得するツイート数 (デフォルトは 20)
990988
991989
Returns:
992990
schemas.TimelineTweets | schemas.TwitterAPIResult: 検索結果
@@ -995,7 +993,15 @@ async def searchTimeline(
995993
# variables の挿入順序を Twitter Web App に厳密に合わせるためにこのような実装としている
996994
variables: dict[str, Any] = {}
997995
variables['rawQuery'] = query.strip() + ' exclude:replies lang:ja'
998-
variables['count'] = count
996+
if cursor_id is None:
997+
## カーソル ID が指定されていないときは20件取得する (Twitter Web App の挙動に合わせる)
998+
variables['count'] = 20
999+
else:
1000+
## カーソル ID が指定されているときは40件取得する (Twitter Web App の挙動に合わせる)
1001+
## 厳密にはより新しいツイートを取得するためのカーソル ID が指定されているときは40件、
1002+
## より古い過去のツイートを取得するためのカーソル ID が指定されているときは20件取得される仕様のようだが、
1003+
## 両者を判別する方法がないので一律40件取得する
1004+
variables['count'] = 40
9991005
if cursor_id is not None:
10001006
variables['cursor'] = cursor_id
10011007
## Twitter Web App で検索すると typed_query になることが多いのでそれに合わせる

0 commit comments

Comments
 (0)