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.

Pages

Click, “Create Page” for a business and follow the steps.

Create Page
Create business page

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.

Business Page

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.

User Token

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.

Instead of APP_ID use your 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.

--

--

--

Information about Data Science and Python Stuff

Recommended from Medium

Foo Bar Challenge — Lovely Lucky LAMBS

Flutter Automation Testing

Async await implementation in ios

Use An API To Get Global Airports

How to use the SendGrid API with Ruby

Java Variables and Data Types

Custom Domain and Security for ShinyProxy with Nginx

Install OpenVAS (Greenbone) 20.08 on Ubuntu 20.04

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
iOSTom

iOSTom

iOS Developer, Go, Java, C#, Blockchain enthusiast, Data junkie

More from Medium

Scrapy Tutorial — Part 4

The ultimate guide for Web Scraping with Selenium

Python Web Scraping | How to Scrape the API of a Real Estate Website

How to web scrape data using Selenium and BeautifulSoup in Python — an example on www.mobile.de

landing_page