Scrape Facebook messages


In the two previous articles, I explained you how to scrape posts and comments from any public page, using the Facebook graph API and a user access token.
In this new article, I'll show you how to read the message but of your own page (you can't gather the messages of public pages, it's not allowed because you need a page access token)
Folow me now to do that:
1. you should create a graph API (if you didn't create it before). if you don't know how to create it, refer you to this article:

2. Then, you should get a page access token:
    2.2. select the name of your app like this:
   2.3. Select Get user access token,
2.4. cross all the check boxes , in order to get access to the messages 




2.5. now, select your page , in this case, you can use this access tken which is temporary (is available for around 1h), but you can get a permanent page access toke.


2.6. in the 'i' , clik on open in Access Token Tool, in order to get a permanent Access token.


2.7. here, clik on Extand Access Token


2.8. then , get the long-lived access token.




 Now, to get the information about your page messages , you can use this url:
https://graph.facebook.com/page_id/threads/?fields=messages{created_time,from,to,message,id}&access_token=page_access_token
this allows you to display these infos on a json format.

form more information about the messages, I invite you to visit this link: https://developers.facebook.com/docs/graph-api/reference/thread/ 
    
 then, I put this python code that allows you to get the messages. you have just to specify the id of your page, and the page access token in the code (page_id, access_tken).
    
    Good luck :)



Comments

Popular posts from this blog