LoginSignup
0
0

More than 1 year has passed since last update.

Tweepyで「API.update_status_with_media」を使って画像付きTweetをするのは推奨されていない。

Last updated at Posted at 2022-05-05

https://docs.tweepy.org/en/stable/api.html#tweepy.API.update_status_with_media
こちらによれば、

Deprecated since version 3.7.0: Use API.media_upload() instead.

となっている。
日本語のTweepy解説記事では多くが「API.update_status_with_media」を利用したサンプルを掲載している。
ちょっとした拍子に動かなくなっちゃうかもしれない。

じゃあどうすればいいんだよ

ドキュメントに書いてあった通り、「API.media_upload」で画像をアップロードしてから「API.update_status」でmedia.idを指定する。

tweet_txt = "あいうえお"
tw_img_pass = "file.png"

media = api.media_upload(tw_img_pass)
api.update_status(status=tweet_txt, media_ids=[media.media_id])

API V2で画像付きツイートできないの?

悲しいことに今日(2022/5/5)現在できないらしい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0