我搜索了论坛并找到了一个线程,我曾在该线程中编写脚本将图片上传到 tumblr。
from tumblr import Api
import sys
def antearaTumblr(blog, email, password):
BLOG=blog
USER=email
PASSWORD=password
api = Api(BLOG,USER,PASSWORD)
#data = open('C:/Users/Kevin/Desktop/python-tumblr-0.1/1329360987775.jpg').read()
api.write_photo('http://www.jonathanworthington.co.uk/wp-content/uploads/2008/07/etc.jpg')
title = ''
body = ''
api.write_regular(title,body)
这确实有效,它使用 write_photo 从互联网上抓取照片并将其上传到我的 tumblr。但是,我不知道如何让它从我电脑上的目录中抓取照片,就像这样....
from tumblr import Api
import sys
def antearaTumblr(blog, email, password):
BLOG=blog
USER=email
PASSWORD=password
api = Api(BLOG,USER,PASSWORD)
data = open('C:/Users/Kevin/Desktop/python-tumblr-0.1/1329360987775.jpg').read()
title = ''
body = ''
api.write_regular(title,data)
它上传成功,但是它上传的只是这个... ÿØÿà...我认为是 jpg 标题。
我找到了这个主题 Post picture to Tumblr using Python但我不知道这些回复到底在说什么。
有谁知道如何使用目录而不是链接让它工作?
此外,我试过这个 https://gist.github.com/1242662但老实说,我只是不知道该怎么做。
感谢我收到的任何帮助。
最佳答案
查看链接的帖子,数据似乎是一个关键字参数,因此您可以这样调用 api.write
:
api.write_regular(title, data=data)
我不知道这是否有效,但 tumblr 的 API 似乎是 well documented .我建议使用 requests
相反,这是迄今为止最好的 Python HTTP 库。上传照片:
import requests
url = 'https://www.tumblr.com/api/write'
data = {'email': your_email, 'password': your_password, 'type': 'photo'}
files = {'data': open('your_image.jpg')}
requests.post(url, data=data, files=files)
关于python - 通过python将目录中的图片发布到tumblr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9305796/