在Facebook墙壁丝毫Python的自动岗位

时间:2018-05-03 19:42:35

标签: python facebook facebook-graph-api bots

我试图创建一个可以自动发布在Facebook墙上的脚本,这个:

import facebook

graph = facebook.GraphAPI(access_token='...')

attachment =  {
    'name': 'Link name',
    'link': 'http://www.example.com/',
    'caption': 'Check out this example',
    'description': 'This is a longer description of the attachment',
    'picture': 'https://upload.wikimedia.org/wikipedia/commons/c/c4/Michelangelo_Merisi_da_Caravaggio_-_Medusa.png',
}

graph.put_wall_post(message='Check this out...', attachment=attachment)

但不幸的是给了我这个错误,我不知道问题出在哪里......

`AttributeError: 'GraphAPI' object has no attribute 'put_wall_post'

2 个答案:

答案 0 :(得分:0)

您的代码应该适用于facebook SDK的V2.0.0,但最新版本使用put_object方法。有关如何使用它的详细信息,请参阅documentation

答案 1 :(得分:0)

使用put_object

  

将给定对象写入连接到给定父级的图形。

     

参数

     

parent_object - 一个字符串,它是该特定的唯一ID   资源。 parent_object是连接或边的父级。   例如,profile是feed的父级,post是a的父级   评论。 connection_name - 指定连接或的字符串   对象之间的边缘,例如,馈送,朋友,群组,喜欢,帖子。   实例

# Write 'Hello, world' to the active user's wall.
 graph.put_object(parent_object='me', connection_name='feed',
                  message='Hello, world')

# Add a link and write a message about it.
graph.put_object(
   parent_object="me",
   connection_name="feed",
   message="This is a great website. Everyone should visit it.",
   link="https://www.facebook.com")

 # Write a comment on a post.
 graph.put_object(parent_object='post_id', connection_name='comments',
                  message='First!')

是你的页面吗?您需要成为该页面的管理员才能发布到新闻Feed。否则,您只能将帖子提交到页面的“帖子到页面”部分。确保用户帐户已配置为“管理员”而非“主持人”。

检查角色:

https://developers.facebook.com/docs/pages/access-tokens#roles

相关问题