问题
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