Tuesday, January 21, 2014

Login with Google Account to Website

This post have Complete Code for Login with google Account .(For PHp Developers)

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 in 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/
                         

Just click on Create Project.

You should get a screen like this,:

                     



 Click on the 1st Red Button [Create New CLIENT ID] ,.
Select Web Application(Assuming you are using this for Web Application)
Fill URL under

Authorized Javascript origins 

and 

Authorized redirect URI 

and click create Create Client ID button.
You should see Client ID and Client Secret like this..
Now Client ID and client Key is successfully generated. To generate Developer API Key.

Click Create New Key, on the below screen.





On clicking you will see, Click Browser Key



.Enter your website URL and click "Create". The API developer key is generated.

You should see a window like this.







Once you have done this, lets look towards code,

We have file google_verification.php, holds information about the keys genrated.
Then we have a Google Client Libary for PHP(src folder) downloable from

https://code.google.com/p/google-api-php-client/downloads/list

Then we have file index.php interacting with Google Client Libraay and generating User Information.

i have not integarted Database part in this post as this is the easy part and  I dint want the code to be complex because of that part.
Although in code, I  have made suitable comments to help you understand the code and also made comments for what to be done for database connection.

 Thats it...Hope this will help.

If you like the Post, please share on facebook and google.

Thanks,

No comments:

Post a Comment

Followers