Python how to do facebook wall post using graph api?

≯℡__Kan透↙ 提交于 2020-01-03 06:33:08

问题


i am trying to post a message into my wall using facebook graph api. I have my access_token. I have tried in my browser using following URL.

https://graph.facebook.com/me/feed?message="Hii friends"&access_token=xxxxxxxxxx

But message is not posted. So i couldn't solve this problem. Finally i want to use this URL inside urllib2.urlopen()

Please Help


回答1:


I recently got posting to facebook to work like so:

import requests

face_token = 'your_token'
post = 'Your Post wowzers'
post.replace(' ', '+')
requests.post("https://graph.facebook.com/me/feed/?message=" + post + "&access_token=" + face_token)



回答2:


You can do it with the graph api like this:

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

If you leave the profile_id blank, it will default to your profile. In the attachment dictionary, you can leave the extra fields that you don't need. First you need to install fackbook-sdk:

pip install facebook-sdk



回答3:


This will most likely not work in the browser. Check out some other threads on stackoverflow for this:

  • How do I update FB Status using Python & GraphAPI?
  • Posting to Facebook wall

Also, check out google, there are many tutorials and frameworks for using the Facebook API with Python.



来源:https://stackoverflow.com/questions/24989753/python-how-to-do-facebook-wall-post-using-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!