代码之家  ›  专栏  ›  技术社区  ›  Sam B.

使用python facebook sdk在facebook上发布更新/消息

  •  0
  • Sam B.  · 技术社区  · 6 年前

    根据我从文档中得到的说明,这是我使用SDK平台的尝试,以及我得到的错误

    In [5]: graph = facebook.GraphAPI(access_token=my_access_token, version="2.12")
    
    In [6]: graph.put_object(parent_object='me', connection_name='feed',
    ...:                   message='Hello, world http://68.183.98.238/blog/best-floor-for-high-traffic-areas')
    ---------------------------------------------------------------------------
    GraphAPIError                             Traceback (most recent call last)
    <ipython-input-6-e8b64d6b32a8> in <module>
        1 graph.put_object(parent_object='me', connection_name='feed',
    ----> 2                   message='Hello, world http://68.183.98.238/blog/best-floor-for-high-traffic-areas')
    
    ~/code/envs/decomagna/lib/python3.6/site-packages/facebook/__init__.py in put_object(self, parent_object, connection_name, **data)
        190             "{0}/{1}/{2}".format(self.version, parent_object, connection_name),
        191             post_args=data,
    --> 192             method="POST",
        193         )
        194
    
    ~/code/envs/decomagna/lib/python3.6/site-packages/facebook/__init__.py in request(self, path, args, post_args, files, method)
        311
        312         if result and isinstance(result, dict) and result.get("error"):
    --> 313             raise GraphAPIError(result)
        314         return result
        315
    
    GraphAPIError: Invalid OAuth access token.
    

    enter image description here

    访问令牌和我从Facebook开发者页面上得到的相同。

    我觉得我还没有提供足够的证明,尤其是代表我发布。

    1 回复  |  直到 6 年前
        1
  •  1
  •   andyrandy    6 年前

    首先:不可能再向用户墙发布消息, publish_actions 权限已弃用。 ( https://developers.facebook.com/blog/post/2018/04/24/new-facebook-platform-product-changes-policy-updates/ )

    也就是说,您可能使用了屏幕截图中的“客户机令牌”,这是错误的。您必须使用所需的权限授权您的用户,并使用生成的用户令牌。

    推荐文章