我有这个小脚本在上个月完美运行
from twython import Twython
import glob
import random
app_key = "XXX"
app_secret = "XXX"
oauth_token = "XXX"
oauth_token_secret = "XXX"
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
def RandomImageTwitt(folder):
#Takes the folder where your images are as the input
images = glob.glob(folder + "*")
image_open = open(images[random.randint(0,len(images))-1])
twitter.update_status_with_media(media=image_open)
RandomImageTwitt("/home/XXX/.reddit-twitter-image/XXX/")
但是现在Twitter已弃用此方法。 Twython告诉我,我应该使用Twython.upload_media,但找不到有关其用法的任何文档。即使是Twython官方网站,仍然列出了带有update_status_with_media的示例。
任何人都知道该怎么做,或者在哪里可以找到一些示例/信息?
最佳答案
好吧,我遇到了同样的问题,我把它弄乱了,并使它正常工作。
我已将其放入您的代码中(尽管未测试)
from twython import Twython
import glob
import random
app_key = "XXX"
app_secret = "XXX"
oauth_token = "XXX"
oauth_token_secret = "XXX"
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
def RandomImageTwitt(folder):
#Takes the folder where your images are as the input
images = glob.glob(folder + "*")
image_open = open(images[random.randint(0,len(images))-1])
#new code starts here
image_ids = twitter.upload_media(media=image_open)
twitter.update_status('hello this is a status',image_ids['media_id'])
RandomImageTwitt("/home/XXX/.reddit-twitter-image/XXX/")
关于python - 如何使用Twython将图像发布到Twitter?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27094275/