Facebook API to Pull Data


API

Updated Jun 28th, 2021

Most clients are not interested in creating content in their website’s backend, they would rather leverage the content the content they post on Facebook.

There are different types of FB integrations are possible, Messenger, Comments, Feed, Pages, Posts, Statuses, etc. It’s important to know what you are trying to accomplish, (most clients want posts integration).

Facebook API Integration

This option is good for a custom-non-WP-plugin approach.

From this link from FB, “The Graph API is the primary way to get data into and out of the Facebook platform. It’s an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

I watched a video here, that explained how to set up your app to be able to make API requests. It’s pretty in depth, not as simple as just getting a key like with the some of the other APIs I’ve seen. See below for notes from this video. There was a worksheet he said you could get but it required submitting up your email.

Facebook oEmbed

Link about this here

WP Plugins:

Smash Balloon Facebook Feed Pro: Article from WP Beginner here. There’s also a free version of the plugin, called Smash Balloon Social Post Feed. This works fine to display text and links from your timeline. However, it will not show photos unless you upgrade to the pro version which has a demo here. This is exactly what we are looking for so it is worth the money. $100 a year for one site, on sale for $40 is a no-brainer based on how long it would take me to learn how to do this on my own. From the dev perspective I can pass this cost along to the client, or buy my own multi-site package and offer as part of the service, (still passing cost along). As far as the client stand-alone mentality this is just another thing they create account and purchase. If I want to continue functionality without the plugin I have bought myself a year’s time to figure out how to do it on my own.

Embed with No Plugin:

Video here about embed.

Here is the FB Link to embed a page. You can embed via a Javascript SDK or an iframe.

Here is the iframe default width:

The iframe max-width of 500 busts out of the container on mobile.

Other:

Integrating Social can be complicated, and expensive. To think this is just for facebook. Some clients may want to pull in data from facebook, twitter, instagram, youtube, etc.

Unrelated to what I am trying to do but I cam across, what is Facebook pixel? Analytics tool that allows you to measure the effectiveness of your advertising by understanding the actions people take on your website.

SmashBalloon Used Easy Digital Downloads for the Stripe Checkout form.

Notes from Facebook API Video

Have to register the client and the client our app/website is the client. Create new app and inside go to settings.

appID = clientId = (from settings)

appSecret = clientSecret = (from settings)

redirectURI = (not so starightforward)

Need to add a product. Click setup button on Facebook login. Click Web ad Paste in your site URL. Now go to settings for the product. FB is very particular about redirectURI; will automatically put a forward slash / at the end of your url but it’s a good idea to put it there anyway. https://whatEvs.com/

URLENCODE (of redirect URI) = Go to the urlencoder.org and paste in https://yourSite.com/ and copy the code generated, (something like htps%3A2F%2Fapi…).

use some data from above to put in your authorization endpoint (browser). Swap out for ClientId, redirectURI, and state. For state, put a 9 digit number but production code you need to generate something unique in app when you call. Then when you receive make sure it matches.

Need to extract from response: the code parameter value. Code is what’s in there but not the &state stuff.

Token Endpoint: get request “htps://graph.facebook.com/v6.0/oauth/… send via curl or postman. What you need from the response is from inside the JSON construct {“access_token”: Blah}. It’s the string that is in the access_token key not including quotes.

Now we can finally call our API!

Resource Access

Find the base request and paste in your access token from the previous step. The example was for simple name and ID.