Python Facebook graph API发布URL及预览
我正在尝试使用Graph API在我的facebook墙上发布一个链接。当我手动将URL放在“Write Something”文本框中时,它会显示URL的预览并发布它。 我尝试通过graph api发布相同的URLPython Facebook graph API发布URL及预览,python,facebook,facebook-graph-api,hyperlink,preview,Python,Facebook,Facebook Graph Api,Hyperlink,Preview,我正在尝试使用Graph API在我的facebook墙上发布一个链接。当我手动将URL放在“Write Something”文本框中时,它会显示URL的预览并发布它。 我尝试通过graph api发布相同的URL import facebook graph = facebook.GraphAPI(access_token) graph.put_wall_post("http://www.channelnewsasia.com/news/world/7-year-old-writes-to-
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图形API
如何从Graph API实现同样的功能 如果要共享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()
如果您将配置文件_id留空,它将默认为您的配置文件。在附件字典中,你可以留下你不需要的额外字段。什么是graph.put_wall_post?@WizKid,我更新了这个问题。我们仍然不知道put_wall_post的作用是什么FacebookAPI中提供的写在FacebookWall上的函数。我是这样的,graph可以访问wall page和用于分享想法的函数write in textbox。如果你不知道SDK的功能,你应该询问编写它的人。是的,我使用了相同的功能,并在2月21日解决了问题