使用 Python 将图片发布到 Tumblr [英] Post picture to Tumblr using Python

查看:19
本文介绍了使用 Python 将图片发布到 Tumblr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 python 将图片发布到 tumblr,特别是:http://code.google.com/p/python-tumblr/

I'm trying to post a picture to tumblr, using python, in particular: http://code.google.com/p/python-tumblr/

#!/usr/bin/python

#!/usr/bin/python

from tumblr import Api
import sys

BLOG='example.tumblr.com'
USER='example@example.com'
PASSWORD='example'
api = Api(BLOG,USER,PASSWORD)
post_data = "picture.png"   
title = "Title of my entry"
body = "this is a story with a picture"

api.write_regular(title, body + post_data)

当我运行它时,结果是博客到达,但不是:

When I run this the result is that the blog arrives, but instead of:

我的条目标题

这是一个有图片的故事

[图片]

我明白了:

我的条目标题

这是一个故事图片图片.png

this is a story with a picturepicture.png

推荐答案

在您当前的代码中,您不是发布图像,而是发送名为picture.png"的字符串.正如 Daniel DiPaolo 所说,您必须使用写照片.例如,write_photo 的参数是图像的链接.

In your current code, you are not posting an image but you are sending a string which is called "picture.png". As Daniel DiPaolo said you have to use write a photo. The Argument for write_photo is the link to the image, for example.

#!/usr/bin/python
from tumblr import Api
import sys

BLOG='example.tumblr.com'
USER='example@example.com'
PASSWORD='example'
api = Api(BLOG,USER,PASSWORD)
api.write_photo('http://example.org/somewhere/lolcat.jpg')

如果你想发送 HTML,你可以创建一个包含你选择的标签的很长的正文.

If you want to send HTML, you can create a body which is long containing the tags of your choices.

title = "life is amazing" 
body = """
_here my html code_
"""

然后用API写

api.write_regular(title,body)

你应该准备好了.

更准确地说;) 如果您想发送数据,您必须打开对象.假设您的图片是lolcat.jpg"

to be more precise ;) in the case you want to send data you have to open the object. Let's say your image is "lolcat.jpg"

data = open('lolcat.jpg').read()

data = open('lolcat.jpg').read()

这篇关于使用 Python 将图片发布到 Tumblr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆