我正在尝试使用Graph API在我的facebook墙上发布一个链接。当我手动将URL放入"Write Something“文本框中时,它会显示URL的预览并将其发布。

我试着通过图形api发布相同的URL
import facebook
graph = facebook.GraphAPI(access_token)
graph.put_wall_post("http://www.channelnewsasia.com/news/world/7-year-old-writes-to-google-for-job-ceo-sundar-pichai-replies/3526608.html")但它会将链接作为文本发布。我使用Facebook-SDK来访问Facebook的图形API。
我如何从Graph API中实现同样的功能?
发布于 2017-04-18 23:03:19
如果您正在共享URL,您将希望使用附件参数,以便在帖子中显示缩略图预览。您必须按照API参考建议的方式添加它:
import facebook
def main():
graph = facebook.GraphAPI(access_token='your_user_access_token', version='2.8')
#if version 2.8 show error use 2.6
attachment = {
'name': 'Link name'
'link': 'https://www.example.com/',
'caption': 'Check out this example',
'description': 'This is a longer description of the attachment',
'picture': 'https://www.example.com/thumbnail.jpg'
}
graph.put_wall_post(message='Check this out...', attachment=attachment, profile_id='your_page_id')
if __name__ == "__main__":
main()如果您将profile_id留空,它将默认使用您的配置文件。在附件字典中,您可以保留不需要的额外字段。
https://stackoverflow.com/questions/42358277
复制相似问题