2014-04-26 105 views
2

上传图片至Facebook墙上我想发表图片到用户的Facebook墙上使用Python和GraphApi。我可能已经发现答案是我想要做的事情是不可能的,但是我希望不会,所以我无论如何都会寻求帮助。通过Python和Graphapi

我可成功认证和后文本到墙上使用:

self.client = GraphAPI(ACCESS_TOKEN)

self.client.put_object( “我”, “进料”,邮件=“MYTEXT张贴在FB墙“)

所以我的问题是什么参数或配置必须使用/以发布从用户计算机(尤其是Windows的图像添加,但任何OS)在墙上。我发现了许多对图像的URL引用的引用,但我想直接从桌面发布到墙。

回答

0

通过我与Python实现的graphapi的工作中,我遇到了这个问题的答案,我问。在某种程度上,可以看到,不可能将图像发布到Facebook墙上(除了使用url链接)。从另一个角度来看,这是非常可能的。你要做的就是将图像添加到相册,添加的图片说明(如果你选择,但它不是必需的),并且图像将被张贴到这张专辑,但它也将出现在Facebook的墙,从而您已将所述图片张贴到墙上。

的图像发布到相册中的代码(我收到的帮助,这从另一个我的做题):

caption = "This will be the description of the image in the album and also the message that appears on the wall" # caption = '' is acceptable if you do not wish to have a message 
albumid = '' # this can be the album id of a facebook album or it can be left blank 
with open("test.jpg","rb") as image: 
     posted_image_id = GraphAPI.put_photo(image, caption, albumid) 

仅供参考,有用于显示图像的Facebook涂鸦墙的另一种选择,但我无法得到它充分的工作,但我会提到它,以防万一有人想弄清楚我做错了什么

如果你知道已经张贴的图像的facebook imageid,理论上(根据facebook Graph API文档中,你可以使用object_attachment在墙贴上引用所述图像,所以代码看起来像这样:

msg = "This is the message that I want displayed on my wall" 
imageid = facebook_image_id #to get this you will have execute a read via the graph api and select the image you want to "reference" on your wall post 
GraphAPI.put_object("me", "feed", message=msg,object_attachment=imageid) 

这为我工作,除了上也看不到图像,我只看到一个空白区域,但空白区域单击,能够和点击时打开了正确的Facebook的图像。所以,我需要弄清楚为什么图像不上墙的出现,但现在我并不需要它,所以也许有一天我会回来这一点。