Skip to content

Commit 3e585a1

Browse files
committed
Fix: [Server][Utils/TwitterGraphQLAPI] OldTweetDeck ユーザーの凍結祭りを鑑み、取り急ぎ X Pro の API キーを使用した API アクセスの一切を回避する
1 parent e1e67d2 commit 3e585a1

File tree

2 files changed

+21
-39
lines changed

2 files changed

+21
-39
lines changed

server/app/models/TwitterAccount.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# ref: https://stackoverflow.com/a/33533514/17124142
44
from __future__ import annotations
55

6-
import asyncio
76
import json
87
import time
98
from typing import TYPE_CHECKING
@@ -55,25 +54,27 @@ async def updateAccountsInformation(cls):
5554
await twitter_account.delete()
5655
continue
5756

58-
# tweepy の API インスタンスを取得
59-
api = twitter_account.getTweepyAPI()
60-
61-
# アカウント情報を更新
62-
try:
63-
verify_credentials = await asyncio.to_thread(api.verify_credentials)
64-
except tweepy.TweepyException as ex:
65-
logging.error(f'Failed to get user information for Twitter account @{twitter_account.screen_name}', exc_info=ex)
66-
continue
67-
# アカウント名
68-
twitter_account.name = verify_credentials.name
69-
# スクリーンネーム
70-
twitter_account.screen_name = verify_credentials.screen_name
71-
# アイコン URL
72-
## (ランダムな文字列)_normal.jpg だと画像サイズが小さいので、(ランダムな文字列).jpg に置換
73-
twitter_account.icon_url = verify_credentials.profile_image_url_https.replace('_normal', '')
74-
75-
# 更新したアカウント情報を保存
76-
await twitter_account.save()
57+
# 2025年11月の OldTweetDeck 絡みの凍結祭りに鑑み、当面バックグラウンドで API アクセスを行う以下の処理を無効化
58+
59+
# # tweepy の API インスタンスを取得
60+
# api = twitter_account.getTweepyAPI()
61+
62+
# # アカウント情報を更新
63+
# try:
64+
# verify_credentials = await asyncio.to_thread(api.verify_credentials)
65+
# except tweepy.TweepyException as ex:
66+
# logging.error(f'Failed to get user information for Twitter account @{twitter_account.screen_name}', exc_info=ex)
67+
# continue
68+
# # アカウント名
69+
# twitter_account.name = verify_credentials.name
70+
# # スクリーンネーム
71+
# twitter_account.screen_name = verify_credentials.screen_name
72+
# # アイコン URL
73+
# ## (ランダムな文字列)_normal.jpg だと画像サイズが小さいので、(ランダムな文字列).jpg に置換
74+
# twitter_account.icon_url = verify_credentials.profile_image_url_https.replace('_normal', '')
75+
76+
# # 更新したアカウント情報を保存
77+
# await twitter_account.save()
7778

7879
logging.info(f'Twitter accounts update complete. ({round(time.time() - timestamp, 3)} sec)')
7980

server/app/utils/TwitterGraphQLAPI.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -502,25 +502,6 @@ async def invokeGraphQLAPI(self,
502502
headers['x-xp-forwarded-for'] = xpff_header
503503
logging.debug_simple(f'[TwitterGraphQLAPI][{endpoint_info.endpoint}] X-XP-Forwarded-For: {xpff_header}')
504504

505-
# CreateTweet / CreateRetweet エンドポイントのみ、Bearer トークンを旧 TweetDeck / 現 X Pro 用のものに差し替える
506-
## 旧 TweetDeck 用 Bearer トークン自体は現在も X Pro 用として使われているからか (ただし URL は https://pro.x.com/i/graphql/ 配下) 、
507-
## 2024/08/08 現在では Twitter Web App 用 Bearer トークンでリクエストした際と異なり、スパム判定によるツイート失敗がほとんどないメリットがある
508-
## なぜこの Bearer トークンが使えるのかはよく分からないが、実際 OldTweetDeck でも同様の実装で数ヶ月運用されている
509-
## 今後対策される可能性もなくもないが実装時点ではうまく機能しているので、推定ユーザー数万人を有する OldTweetDeck の実装に合わせる
510-
## 2025/05/13 現在は FavoriteTweet / SearchTimeline も同様の対応が必要
511-
## UnfavoriteTweet はこの対応をしなくても動作するが、対になる操作のためリストに入れている
512-
## ref: https://github.com/dimdenGD/OldTweetDeck/blob/v4.0.3/src/interception.js#L1208-L1219
513-
## ref: https://github.com/dimdenGD/OldTweetDeck/blob/v4.0.3/src/interception.js#L1273-L1292
514-
## ref: https://github.com/dimdenGD/OldTweetDeck/commit/7afe6fce041943f32838825660815588c0f501ed
515-
if endpoint_info.endpoint in [
516-
'CreateTweet',
517-
'CreateRetweet',
518-
'FavoriteTweet',
519-
'UnfavoriteTweet',
520-
'SearchTimeline',
521-
]:
522-
headers['authorization'] = self.cookie_session_user_handler.TWEETDECK_BEARER_TOKEN
523-
524505
# Twitter GraphQL API に HTTP リクエストを送信する
525506
try:
526507
if endpoint_info.method == 'POST':

0 commit comments

Comments
 (0)