Skip to content

Commit a312086

Browse files
committed
Fix: [Server][Routers/TwitterRouter] 画像アップロード時にチャンクアップロードできていなかったのを修正
あまりに凡ミスすぎて涙… 嘘だよな? 今回予想以上に時間手こずりすぎている…
1 parent cc78124 commit a312086

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/app/routers/TwitterRouter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,16 @@ async def TwitterTweetAPI(
304304
try:
305305
# 画像をアップロードするタスク
306306
# TODO: 本来はここもヘッドレスブラウザ経由で送信すべきだが、おそらく画像の受け渡しが面倒なのと、
307-
# upload.x.com のみ他の API と異なり v1.1 時代からほぼそのままでセキュリティも緩そうなので当面これで行く…
307+
# upload.x.com のみ他の API と異なり v1.1 時代からほぼそのままで Bot 対策も比較的緩そうなので当面これで行く…
308+
logging.info(f'[TwitterRouter][TwitterTweetAPI] Uploading {len(images)} images...')
308309
tweepy_api = twitter_account.getTweepyAPI()
309310
image_upload_task: list[Coroutine[Any, Any, Any | None]] = []
310311
for image in images:
311312
image_upload_task.append(asyncio.to_thread(tweepy_api.media_upload,
312313
filename = image.filename,
313314
file = image.file,
314315
# Twitter Web App の挙動に合わせて常にチャンク送信方式でアップロードする
315-
chunk = True,
316+
chunked = True,
316317
# Twitter Web App の挙動に合わせる
317318
media_category = 'tweet_image',
318319
))
@@ -322,6 +323,7 @@ async def TwitterTweetAPI(
322323
## ref: https://developer.twitter.com/ja/docs/media/upload-media/api-reference/post-media-upload-init
323324
for image_upload_result in await asyncio.gather(*image_upload_task):
324325
if image_upload_result is not None:
326+
logging.info(f'[TwitterRouter][TwitterTweetAPI] Uploaded image. [media_id: {image_upload_result.media_id}]')
325327
media_ids.append(str(image_upload_result.media_id))
326328

327329
# 画像のアップロードに失敗した

0 commit comments

Comments
 (0)