Python Web Scraping Part: 7 Facebook SDK
Over the last few articles I explained how to scrape data from a single site. As I continued down this path I started to see how useful and powerful data really is. In this article I am going to show you how to use the facebook api. By the end of this article you will be able to get tokens, connect to your user and business page and send a facebook post all using python.
Let’s start off by creating a page because I am amusing you have a facebook user profile already created. So head over to your timeline and navigate to the pages on the left hand side.
Click, “Create Page” for a business and follow the steps.
If everything goes correctly your business page should be created. Navigate back to your timeline, click on pages and your new business page should be listed.
Now that I have both a user profile and a business page I want to be able to post content by using the facebook sdk and python.
Head over to the facebook developer page and create a new app https://developers.facebook.com/. Once you create a new app click on graph API explorer.
If you look on the right hand side you have the ability to create different access tokens. User tokens control your user profile and page tokens control your business page. I ended up creating both.
Next, create a python script called facebook_client.py and create a variable called page_token to store your access_token. The final thing todo is install the facebook-sdk.
pip install facebook-sdk
Verify that everything is sent up everything correctly. Also instead of app_id it should be page_id.
I did not have a clue what the page_id was or where to find it, some say you can find it on your profile page but the easiest way for me was to look at my facebook url.
If your page url is structured like this: https://www.facebook.com/honeypot-123432423 then your page_id is 123432423. I think I am going to save the facebook api calls for the next article. So, If you learned something click the clapper and stay tuned. If you messed any of my previous articles check them out below.
Python Web Scraping PART:1
In the next few articles I am going to talk about my web scraping experience with python. I will explain the pro/cons…
Python Web Scraping Part: 3
In my last two articles I talked about web scraping with python, how to set up a python development environment…
Python Web Scraping Part: 4
My last few articles have been about web scraping with python. In this article I am going to talk about digital…
Python Web Scraping Part: 5
Over the past few articles I have talked about python, web scraping and digital marketing. In this article I am going…