2017-02-21 48 views
0

我想使用图形API发布我的facebook墙上的链接。当我手动将URL写入“Write Something”文本框时,它会显示URL预览并发布。 Manual Post on FB wallPython Facebook图形API发布URL的预览

我试图通过图形API

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") 

发布相同的URL,但它的链接后为文本。我正在使用Facebook-SDK访问Facebook图形API。

如何从Graph API实现相同功能?

+0

什么是graph.put_wall_post? – WizKid

+0

@WizKid,我更新了问题。 – pratibha

+0

我们仍然不知道put_wall_post是什么 – WizKid

回答

2

如果您要共享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空白,将默认为您的个人资料。在附件字典中,您可以保留不需要的额外字段。

+0

是的,我使用了相同的方法,并于2月21日解决了这个问题 – pratibha

相关问题