从GAE Images API转换后的图像上传到Facebook

时间:2012-07-19 23:30:59

标签: python image google-app-engine facebook-graph-api

有谁知道如何将GAE Images API Image对象转换为“像对象一样的文件”?

我正在尝试将我从GAE Images API转换为Facebook的图像上传到Facebook。我正在使用execute_transforms函数,它返回图像的“图像表示”。 我试图使用以下代码上传它,但我得到一个FB API错误“没有上传的图像”

img = images.Image(ORIGINAL_IMAGE)
img.crop(0.0, 5.0/img.height, 713.0/img.width, 644.0/img.height)
output = img.execute_transforms(output_encoding=images.PNG)
graph = fb.GraphAPI(access_token)
graph.put_photo(output, 'Look at this cool photo!')

我认为问题是输出不是put_photo要求的“像对象这样的文件”,但是GAE文档没有用于转换为“像对象这样的文件”的功能。尝试创建临时文件并写入它们,但GAE不允许写入文件系统。我也尝试写一个StringIO对象,但是没有用。

由于

1 个答案:

答案 0 :(得分:2)

使用StringIO

enter code here

import StringIO

graph.put_photo(StringIO.StringIO(output), 'Look at this cool photo!')

阅读http://docs.python.org/library/stringio.html

上的文档