Hey, guys!
Today I want to go over how to auto-post your content from PHP to your own Facebook timeline.
I've planned a project for my blog for a while now... and I wanted to program an auto poster that could post simultaneously to:
But for the sake of this article, I will cover only the Facebook auto poster.
THE GOAL: I want to click a button and make my content appear on my Facebook timeline.
Let's say I want to upload a photo to Facebook.
Here's an example PHP code for auto posting an image to Facebook:
fbpost.php
Download this PHP file here.
Note: You have to have {app-id}, {app-secret} and {access-token} filled out... I'll walk you through how to get it below...
Also, make sure you have the right path to your image...
Before you can run this code you need a few things first.
Things you will need:
Ok, now you know what we need let's go step by step.
STEP 1: DOWNLOAD PHP SDK
Go to the link: https://github.com/facebook/php-graph-sdk and download. Put the files on your server.
STEP 2: CREATE FACEBOOK APP
Go to: https://developers.facebook.com/apps and create a Facebook app...
In my case, I created a "test" app first. So I could test it while I'm programming.
It'll look like this:
Name it and Create App Id.
After you fill everything out, you will get to a screen like this:
Next, Click on Choose Platform.
And choose: "Website (www)"
Now you have the {app_id} and {app_secret}. Take those variables and put them in the code above...
STEP 3: GET A FACEBOOK TOKEN
Great! We are getting there...
The last thing we need to get is the facebook {access-token}.
This is how we do it.
We need to run a code on your server.
fbtoken.php
Download this PHP file here.
There's another way to get this string if you don't prefer using fbtoken.php...
STEP 4: INPUT ALL OF THE VARIABLE in the fbpost.php
You have the {app_id} and {app_secret} from step 2.
And now when you run the fbtoken.php you need to login into Facebook and then you will get a long string...
Take that long string and copy and paste into fbpost.php under $accessToken.
Now you are ready to post. BOOM!
When you execute your PHP it will post to your FB timeline.
DONE!
Go to your Facebook page.
The image should be there...
Hope this helps... Enjoy!
Sincerely,
You passive income guy