How can i get all my facebook posts using python code and facebook graph api.
i have tried using this code:
import json
import facebook
def get_basic_info(token):
graph = facebook.GraphAPI(token)
profile = graph.get_object('me',fields='first_name,last_name,location,link,email')
print(json.dumps(profile, indent=5))
def get_all_posts(token):
graph = facebook.GraphAPI(token)
events = graph.request('type=event&limit=10000')
print(events)
def main():
token = "my_token"
#get_basic_info(token)
get_all_posts(token)
if __name__ == '__main__':
main()
I am getting a error that says,
“GraphAPIError: (#33) This object does not exist or does not support this action”.
Seems like all the other stackoverflow questions are very old and does not apply for the newest version of facebook graph API. I am not entirely sure whether u can do this using facebook graph api or not.
if this is not possible using this technique, is there any other way i can get my posts using python?
please note that function get_basic_info() is working perfectly.
2
Answers
I have solved this problem with the help of the first answer by @luschn I was making one more mistake, that is using events for getting all my posts.instead i should have used
me/posts
in my code. Here is the function that works perfectly in version 6.Here, the
post["data"]
only gives first 25 posts, so I have usedposts["paging"]["next"]
link to get the next page as long as there is the next page.I assume you want to get user events: https://developers.facebook.com/docs/graph-api/reference/user/events/
Be aware:
Either way, the API would not be
type=event&limit=10000
but/me/events
instead.