Php apps for facebook

How to Make a Facebook App: Tutorial

Currently Facebook application development is one of the most popular projects for PHP developers. After we have implemented several Facebook applications we decided to share our knowledge with other developers who are just starting to learn this technology.

Facebook allows you to integrate third-party applications with its core: on one hand it allows application to receive access to Facebook implemented features, on the other hand, Facebook expands its features using third-party developers. Such apps could be placed on any external server and could be created almost on any programming-language such as PHP, Python, Java or C#. Thus Facebook application is any app working in Facebook context.

There are 3 ways to integrate your application into Facebook and respectively 3 types of Facebook apps:

  • FBML-apps (Canvas Application) – based on subset of HTML with adding own tags (this is FBML), simplified JavaScript with support of common dialogues. In this type of Facebook apps CSS features are also limited. In work Facebook requests FBML-page from your application server, translates it in HTML and displays app in canvas. For now this type of application is obsolete and isn’t recommended for usage.
  • iFrame-apps – can also use FBML-tags (if respective library is connected), but based on standard HTML, JavaScript as well as CSS. When user requests application web-page, app loads in iFrame-element from web-site where this app was placed. As a result, your app is displayed in common Facebook frame.
  • External apps – are usual web-sites with possibility to login using Facebook account. There are also different social plugins and buttons for interaction with your Facebook account.

Creating a Facebook apps

1. Create

The first you should do is to activate your Facebook account. To create an application click on a link. The page you’ll see is also an application, so you will be asked to confirm addition of this application and its access to your profile.

Читайте также:  Extends java lang runtimeexception

After this, click on a button on the right top called “Create new application”. In the resulting frame write down the name of your Facebook application, agree with Facebook rules and follow the instructions.

2. Set up the Application

So, you are on application edit screen. On the left are tabs for main settings.

Creating a Facebook app: step one

On About tab you can change a name of your Facebook app and its description, load logo and icon to allow user to recognize the app, language and email if you want to receive messages from your application.

On Web Site tab enter the internet-address where the main page of your Facebook application is placed (in the end of URL there should be / ) and the domain name.

Creating a Facebook app - site and domain URL

Also you should choose type of app as iFrame. This type is more convenient and up to date (see types of Facebook apps above).

Creating a Facebook app - canvas type

The next step placed in “Facebook Integration” tab – specify there a Canvas Page and Canvas URL.

Let’s assume you have web-application available at http://www.example.com/application/. To set up Facebook application you should enter the name of application. For example, we’ll use your_app as a name of app and web-page name. If user clicks on URL http://apps.facebook.com/your_app/, he’ll see the content of web-page http://www.example.com/application/ loaded on Facebook.

Creating a Facebook app - canvas page and URL

3. Integrate

Below is source code of application usually called “Hello, World!”:

‘app_id’, ‘secret’ => ‘app_secret’, ‘cookie’ => true, )); $session = $facebook->getSession(); $me = null; // Session based API call. if ($session) < try < $uid = $facebook->getUser(); $me = $facebook->api(‘/me’); $myFriends = $facebook->api(‘/me/friends’); > catch (FacebookApiException $e) < error_log($e); >> $url = $facebook->getLoginUrl( array(‘req_perms’ => ‘read_friendlists’, ‘canvas’ => 1, ‘fbconnect’ => 0, ‘next’ => ») ); ?>

Hello WORLD!

If you want to see friends’ faces click here.

Friends:

‘>

To make it work properly you should download PHP SDK https://github.com/facebookarchive/facebook-php-sdk.

Creating a Facebook app - App with scroll bar

Canvas size

As your application loads on Facebook, you should now about size restriction of user interface. Facebook application web-page shouldn’t exceed 760 pixels in width. Application can be of any height, but if height exceeds limits of Facebook page you’ll see a scroll bar. Certainly you can get rid of it using “iFrame Size” option in application setting and with the help of setAutoResize() function from JavaScript SDK.

Creating a Facebook app - Canvas size

The code below resizes iFrame to Facebook page size:

Creating a Facebook app - Ready!

So, after these simple settings your application should work at http://apps.facebook.com/your_app/, but how to make full Facebook app from it read in the further articles …

Need to add Like button? Read How to Add a Facebook Like Button on our site.

Читайте также:  Многомерная линейная регрессия python

About the authors:
PHP Development Department at NIX Solutions.
Want to see what we do? That is easy in our PHP Web Development Portfolio.

Источник

How To Add Facebook Login to PHP Website

Long registration forms that are a huge hassle to fill and a real pain to validate are now a thing of the past. These days, developers have worked around this thorny UX issue by using Facebook Login for their applications.

facebook login in php

Facebook offers an excellent alternate to the traditional form based login process that has long been a part of the PHP applications. The idea is very simple; you just have to put a Facebook button on the registration page. Next, save the user data after successful login. In this article, I will explain how you can add Facebook Login to PHP apps and get the users’ data.

How to log in with Facebook via/using php? It consists of only four steps to login with Facebook PHP SDK:

  1. Create a Facebook application.
  2. Create an application on the server.
  3. Download Facebook SDK.
  4. How can I initialize PHP SDK on Facebook and Get User Information.

Create an Application in Facebook

To implement Facebook Login system for the application, the first step is the creation of an app through the Facebook account.

Sign into the Facebook and go to developer.Facebook.com .

create app

Click Add New App button and select Website as the platform.

select platform

Stop Wasting Time on Servers

Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.

Enter the app’s name, an email id and select a category for the application. Now click Create App Id button. This will create an app in Facebook.

add facebook app

Now go to Settings, where the App Secret and App ID could be found. These ids will be used in the PHP application. Remember to add the website’s URL in App Domains.

Down the page, Click the Add Platform tab. Add website as a platform and enter the URL of the

add new domain

This finishes the creation of the Facebook App. The next step is to create a server on a fast and best hosting for php platform. I have opted for Cloudways PHP stack server.

Create an Application on Server

To create a PHP server on Cloudways, signup and launch a PHP server on it. For reference, you can follow our guide on hosting PHP on Cloudways.

Visit the server and launch the SSH terminal. Login to SSH by using the master credentials.

Читайте также:  License key for php tools

ssh-terminal

Go to the application folder by running the following command

$ cd applications//private_html/

Download Facebook SDK

Composer is the recommended method of installing libraries on the platform and I will use it to install Facebook SDK.The first step is the creation of a composer file. In the SSH terminal run composer init command and add the required information to it. It will create a composer.json file in the application folder. Add the following code in composer.json.

Now run composer install command in SSH to finalize installation of Facebook SDK.

How can I initialize PHP SDK on Facebook and Get User Information

It is now time to initialize Facebook SDK and get access_token from Facebook. After authenticating the token, the user info will be fetched and the view will be redirected to the profile page that shows the user information.

Create two files in the application folder; Index.php and Profile.php.

Add the following code to index.php file. Comments are added to explain the code.

Once done, go to the application URL in browser. You will see the Facebook button for login. Click it and the page will redirect to Facebook login page. Sign into the Facebook account. After successful login, the page will be redirected to the profile page.

Add the following code to profile.php to show the retrieved information. For the purpose of this tutorial, I will retrieve user id, Facebook profile picture, name and email.

As you can see, the information is presented in a very simple format.

Conclusion

In this tutorial, I demonstrated how to integrate Facebook Login button in your PHP apps. This will do away with the hassles of filling in and parsing long registration forms. If you need to ask a question about the code or wish to add to the conversation, please leave a comment below.

Q: Why use Facebook Login in PHP websites?

A: Using Facebook login in your PHP website helps your visitors to login directly from their Facebook accounts. It allows them to share articles, add comments etc. directly from their Facebook profiles.

Q: What library to use for Facebook login in PHP?

A: You can use Facebook SDK which is a powerful PHP library built with advanced features for integrating Facebook Login in PHP websites.

Share This Article

Customer Review at

“Cloudways hosting has one of the best customer service and hosting speed”

Sanjit C [Website Developer]

Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways — A Managed PHP Hosting Platform. Besides his work life, he loves movies and travelling.

Источник

Оцените статью