+234-703-382-3104, +234-806-729-6988    editor@witicles.com
Witicles™ on Facebook Witicles™ on TwitterWiticles™ on Google+Witicles™ BlogSend Email to Witicles™
Witicles.com





Author Box


Free Online Articles EditorFree Online Articles Editor
We challenge the minds of people towards mental and attitudinal shift and National transformation. We are the Editorial team of Witicles.com & Witicles.com.ng. Promoting knowledge for all!
Joined 5 years ago
From Abuja, Nigeria
Total Articles 154

Recent Articles From Author

# Morata is mentally fragile like Saponara – Sarri
# 4 step explanation of how Arsenal's 3-4-3 formation under Unai Emery works
# 5 Problems for Maurizio Sarri at Chelsea
# Real Madrid superstar wants to leave, Philippe Coutinho tells Barcelona to sign €150 million Premier League superstar, and more transfer news

Namecheap.com Namecheap.com
Shop for Books online in Nigeria at kpiBooks.com.ng Order your favourite books online now, Save the stress & Pay online or with cash at Your Doorstep!


We help our esteemed clients develop web strategy that works!
Call us @ +234 803 578 3880
Article Category >>>Traffic Generation

How To Automatically Post to a Facebook Page using PHP Facebook SDK

By Free Online Articles Editor       May 18, 2015



How To Automatically Post to a Facebook Page using PHP Facebook SDK



During my weekends/time off I tend to watch quite a lot of sport, with the English Premier League (EPL) being one of my favourite things to support. As such, I created and run an EPL facebook page dedicated  to covering fixtures, results, and other news.

Now this all good fun and I enjoy doing it, but week after week, month after month of posting all the fixtures the day before and posting the results the day after gets a little tedious, especially if I’m short on time. So being the geek I am, I decided that I could easily automate these, and so I did, using the PHP facebook SDK.

It was actually pretty straight forward, the hardest bit was trying to find websites which would give me the information in a straight forward and easy way. In the end, I decided to go with the offical Premier League website, as not only is it the correct information it is also laid out in a way which makes it easy to retrieve.

So putting my previous posts into good use I used curl to scrape the website and Xpath to dissect it into the important parts (namely the home and away teams, the location, and the final score).

Once I have this important information I can then go away and use the PHP facebook SDK to post a status to my EPL News feed which I will show you how to do now.

Firstly, you will need to create a facebook application which will be integrated in a website. After you’ve created the app you will want to fill out the website URL and hit save. This URL is going to be where the PHP app you are going to create will be stored (ie http://devhour.net/fbapp).

PHP facebook SDK - Facebook Application

EPLNewsFeed Facebook Application

 

Next up you’ll need to run the following URL to authorize your app to manage your pages and other such permissions. Remember to replace [APP_ID] and [SITE_URL] with both your facebook APP ID and the website you entered above. You will be prompted to grant access to your app (click Allow).

https://graph.facebook.com/oauth/authorize?client_id=[APP_ID]&scope=offline_access,publish_stream,manage_pages&redirect_uri=[SITE_URL]

It will then redirect you back to the URL of the site you specified in the app. If you look closely though you’ll notice that on the end of the url is ?code=aBuNcHoFgIbBeRiSh. Copy everything after the ?code= and keep it in a safe place for now. You’re going to need it in a second.

The next step is to get the long lasting access token which will allow you to keep posting without having to authenticate yourself every time (this is vital to making this whole script automatic). So again go to the following URL and replace [APP_ID], [APP_SECRET], [SITE_URL], and [CODE] (the one you just previously copied).

https://graph.facebook.com/oauth/access_token?client_id=[APP_ID]&redirect_uri=[SITE_URL]&client_secret=[APP_SECRET]&code=[CODE]

If all went well you’ll be redirected back to your website and on the screen you should see:

access_token=…….

Store this somewhere because it’s very important :)

Now the fun can start. Firstly, you can test the access token by going to the Facebook Graph API explorer, pasting the token into the Access token field and trying the following:

PHP facebook SDK - Graph API

Facebook Graph API Explorer

This will post a test message to your page which will indicate that the access token you have is good to go. Now on to the code…

Before we write any code on our end, you’re going to have to download the PHP facebook SDK from the github repo. Download and store these files somewhere handy and feel free to jump into the examples are have a bit of a play.

On our end however, the first thing we are going to is create a php file and reference the facebook sdk and enter some variable details (fill out as necessary).

Now we go ahead and create a new facebook instance using our newly created app details.

The next little piece of code will loop through the pages that you manage and find the PAGE_TOKEN which matches the PAGE_ID you specified. This will allow you to post to that pages wall as the page rather than you.

Taking all the information we have so far received we can now go ahead and post to the pages wall.

And that’s it. It’s actually really straight forward and easy to do. Feel free to play around with it and I’d be interested in seeing what you can come up with



  
1607


If you need to re-publish this ARTICLE, please cite this article - (https://witicles.com/how-to-automatically-post-a-page-using-php-facebook-sdk-359.html) and the Writer (Free Online Articles Editor)

Do You Find This Article Helpful?


Article Tags: how to post, automatically, facebook fan page, fan page, post to facebook, php sdk
Save the Stress, Shop for Books Online in Nigeria - kpiBooks.com.ng
Article Source
Free Online Articles EditorAbout Free Online Articles Editor
Free Online Articles Editor Free Online Articles EditorFree Online Articles EditorFree Online Articles EditorFree Online Articles Editor

  

http://www.devhour.net/automatically-post-page-using-php-facebook-sdk/





Social Sharing
If You Enjoyed This Article; Then, Share It On Your Social Network



     Copy This Short Link To The Article: http://i.witicles.com/qCsLE How To Automatically Post to a Facebook Page using PHP Facebook SDKHow To Automatically Post to a Facebook Page using PHP Facebook SDKHow To Automatically Post to a Facebook Page using PHP Facebook SDKHow To Automatically Post to a Facebook Page using PHP Facebook SDK



Post Comment


Article Comments

No comment found! Be the first to share your thoughts on this article!



Namecheap.com
Related Articles




Author's Articles





My Accounts Categories Useful Links Affiliate Links Follow Us
Witicles.com is not a mere article directory; but Trusted Online Article Directory of syndicated articles on 27 core topics, including health and fitness, finance, business and economy, life improvement, real estate, politics, leadership, management and education. Authors publish articles for free and share knowledge with potential customers.


Lost Password
Sign In
Sign Up
News and Society (169)
Self Improvement (149)
Business and Economy (103)
Leadership (110)
Politics (74)
Arts & Entertainment (44)
Health & Fitness (126)
Religion and Kingdom (58)
Real Estate (16)
Computers & Technology (21)
About Us
Advertise With Us
Contact Us
How To Submit Articles
Article Writing Tips
Sitemap





Leadersoil
Hubpile
Pay4ebooks
kpiBooks
Fridayposts
Flickers of Hope Foundation





CentreNDL on Facebook  Facebook

CentreNDL on Twitter  Twitter

CentreNDL on Google+  Google+

CentreNDL Blog  Blog

Send Email to Hubpile  Email