Skip to main content

Login with Facebook Account PHP Code

Hello All.

In the previous post, we have explained the Login with Google..


This post have Complete Code for Login / Sign In with Facebook Account for PHP Code
As you all know, FB is as popular as Google, so Login With Facebook is also a very important par of a website,

Below is the detailed explanation for complete procedure starting from creating  a  Facebook app to getting the complete details of user logged in .


Download Source Code

Live Demo


Starting is with create an APP for your site .

Note : You should log in to your Facebook account before moving ahead.

Go To https://developers.facebook.com/

Create an APP using the menu  APP appearing on developers toolbar on this page
   

The Following popup appears


 Fill in the details and CREATE APP

After this the APP dashboard appears .

The dashboard has the App Id




Though the app id is the only required field for login , in backend the process the URLs ie the domain url assigned to APP and that of the Facebook login invoking page .
So next step is to add the domain or Platform to the App. So move to the Settings Tab .
Theres the ADD PLATFORM . Click on it and the following popup appears . Click on website and add the url .














After being done with this , the following page is shown


















We are done with the App Creation and hopefully you have noted down the App Id .


Now the second phase , The Facebook Login using javascript .
Create a page and add the following code to it , replacing the appId variable .





The output for this page is follows












The above is the data received from the facebook after the user is successfully Logged In .
The data can be used to register any user or display their information on our website .

Thats all .

Other Related Posts

Login With Google Using php

http://learnandsharetoall.blogspot.in/2015/09/what-is-natural-language-processing.html


You can also check our Microservices post
Introduction to Microservices

Comments

  1. Thanks ankit... I'm gonna use both, Login with facebook and Google in my website.. :)

    ReplyDelete
  2. Thanks a lot really the post is very much useful ..... but i am facing one problem ..... after getting the user information from server how to store them in database .... i how to invoke a function that will store the details after the data has been fetched ? .......

    ReplyDelete
    Replies
    1. json is directly supported in javascript ..
      so in FB.api use the following

      var param=JSON.parse(response);
      var id=param.id ;
      var name=param.name ;

      similarly other values .

      you can now use these values to submit form using javascript or jquery .

      Delete
  3. thanx for provide this code but i have not access the primary email id. how to this possible...

    ReplyDelete

Post a Comment

Popular posts from this blog

What is MonGoDB??

Share on Google Plus Now a Days, we are hearing a lot about MongoDB.

So, in this post I will try to briefly introduce to MongoDB.

MonGoDB is "Non-Relational, JSON, Document Store".

Explaining in detail,

Non-Relational, --> The DB we use most like SQl, Oracle are Relational DBs(RDBMS). They do have the fixed schemas, lots of tables. So Non-relational in nothing like that.

JSON : (JavaScript Object Notation) : It is basically a document with information in the form of key value pair.

for example,

{
   name:"lorem",
   address:"ipsum
}

thats it. 
A simple JSON document where name and address are key
and "lorem" and "ipsum" are corresponding values.

So, MongoDB is the Non Relational database which stores information using DOCUMENT and that document is a JSON document.

MongoDB stores collections of documents.
(Consider the above exxample as collection  "Person"  with a document)(will elaborate it later more)


Need of MongoDB:
The Databases we use…

Login with Google Account to Website using OAuth2.0 with PHP / Javascript

This post have Complete Code for Login / Sign-in  with google Account  using PHP / Javascript with oAuth2.0

Basically today we have seen almost every website needs you to register yourself before you can post or take part in any discussions to the website. But it become a tedious task to register and login to many different sites. Solution is to provide the users the option to Login with existing Google / Facebook account as almost everyone have Facebook and Google account.

In this post, I am going to explain how to integrate the Google Login / Sign in  for your website.

Download Source Code

Live Demo



For this,  First you need to create your Client ID, Client Secret and your developer API key.

For this go to https://code.google.com/apis/console/


Click on the button Create Project. A new window will open up like this :













Enter the Project name and submit on Create.

Wait for new seconds, the new page will open like this.



On the left menu, click on API & Auth and click on credentails. Then…