小编Gia*_*ynh的帖子

如何使用 Twitter API V2 和 Tweepy Python 发布带有媒体(图片)的推文?

我正在尝试使用 Twitter API V.2 和 Tweepy 创建我的第一个 Twitter 机器人。所以我可以发布简单的文本推文,但我还没有找到如何使用媒体(图片)发布推文,那么我该怎么做?(我看到有人说“你不能使用 twitter API v2 发布媒体推文...你需要使用 API V 1.1”,所以如果这是真的,我如何使用 Twitter API V1.1 而不是 API V2 ?)

如果你能帮助我的话谢谢你^^

这是我的实际代码:

from io import BytesIO
from PIL import Image
import tweepy
from tweepy import API

consumer_key = "APP_KEY"
consumer_secret = "APP_SECRET_KEY"
access_token = "TOKEN"
access_token_secret = "SECRET_TOKEN"

client = tweepy.Client(
 consumer_key=consumer_key,
 consumer_secret=consumer_secret,
 access_token=access_token,
 access_token_secret=access_token_secret
)

response = client.create_tweet(
  text="Just a dummy tweet",
  # in_reply_to_tweet_id= 1484105392598749186 <--- Reply to a tweet by ID

)

print(f"https://twitter.com/user/status/{response.data['id']}")
Run Code Online (Sandbox Code Playgroud)

python twitter tweepy

9
推荐指数
2
解决办法
6927
查看次数

标签 统计

python ×1

tweepy ×1

twitter ×1