7

当通过 Open Graph API 制作墙贴时,Facebook 需要一种方法在墙贴中呈现图像。

当我将此链接复制并粘贴到 facebook.com 上的 Facebook UI 并以这种方式发布时,墙上的帖子最终看起来像这样:

FB墙贴中成功渲染的图像

但是,当我尝试使用 Facebook Python 库以编程方式访问我的墙时,使用以下代码,图像不会呈现:

graph = GraphAPI(valid_access_token)
graph.put_wall_post(message='https://s3.amazonaws.com/dotellapptest/review_photos/enlarged/811..OJUzXI76Rw6J2Zj_vZyWNw.png')

产生这个:

不成功的 Facebook 墙贴与图像

如何使用 Facebook API 在我的墙贴中嵌入图像?

4

1 回答 1

4

通过附件使用link字段而不是字段message

def put_wall_post(self, message, attachment={}, profile_id="me"):
    """Writes a wall post to the given profile's wall.

    We default to writing to the authenticated user's wall if no
    profile_id is specified.

    attachment adds a structured attachment to the status message
    being posted to the Wall. It should be a dictionary of the form:

        {"name": "Link name"
         "link": "http://www.example.com/",
         "caption": "{*actor*} posted a new review",
         "description": "This is a longer description of the attachment",
         "picture": "http://www.example.com/thumbnail.jpg"}

    """
    return self.put_object(profile_id, "feed", message=message,
                           **attachment)

https://github.com/pythonforfacebook/facebook-sdk/blob/master/facebook.py#L142

http://developers.facebook.com/docs/reference/api/user/#links

于 2013-01-14T00:07:42.323 回答