AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



google-login: How to enable sign in with google or googleplus on my website?

I want to enable the sign with google feature on my website. Please describe step by step process. Thanks in advance.

google x 3
login x 5
Posted On : 2013-12-16 22:22:09.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939091
up-rate
6
down-rate

Answers


First of all create an app for your website on google.
1. To do so first you have to create a project on https://cloud.google.com/console Enter the Project name and Project ID which is available and follow the steps.

2. In the sidebar on the left, select APIs & auth. In the displayed list of APIs, make sure the Google+ API status is set to ON.

3. In the sidebar on the left, select Registered apps. At the top of the page, select Register App. Fill out the form and select Register. Now follow the following steps:
I. Expand the OAuth 2.0 Client ID section.
II. In the Web origin field, enter your origin i.e. If you are gonna enable the sign in option on www.example.com fill http://www.example.com and press Enter and also add a new one http://localhost:8080(optional)
III. Enter the redirect URI.
IV. Now copy the CLIENT ID

4. To make it better click on consent screen you can upload logo and Product name.

Now it´s almost done, Following is the code to be pasted on your web page :
-----------------------------------------------------------------------------------------------------------------------------------------
<script type="text/javascript">
(function() {
var po = document.createElement(´script´); po.type = ´text/javascript´; po.async = true;
po.src = ´https://apis.google.com/js/client:plusone.js´;
var s = document.getElementsByTagName(´script´)[0]; s.parentNode.insertBefore(po, s);
})();
function signinCallback(authResult) {
if (authResult[´status´][´signed_in´]) {
document.getElementById(´signinButton´).setAttribute(´style´, ´display: none´);
gapi.client.load(´plus´,´v1´, loadProfile);
} else {
console.log(´Sign-in state: ´ + authResult[´error´]);
}
}

function loadProfile(){
var request = gapi.client.plus.people.get( {´userId´ : ´me´} );
request.execute(loadProfileCallback);
}
function loadProfileCallback(obj) {
profile = obj;
email = obj[´emails´].filter(function(v) {
return v.type === ´account´;
})[0].value;
displayProfile(profile);
}
function displayProfile(profile){
var name=profile[´displayName´];
//you can store this information in database
document.getElementById(´name´).innerHTML=name;
document.getElementById(´email´).innerHTML=email;
}
</script>
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="XXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-height="tall"
data-width="wide"
data-scope="https://www.googleapis.com/auth/plus.profile.emails.read"></span></span>
<div id="name"></div>
<div id="email"></div>

-----------------------------------------------------------------------------------------------------------------------------------------
In the above code set the data-clientid="Your Client Id Recently copied by you."

To customize the button you can change the attribute for more details : https://developers.google.com/+/web/signin/reference#sign-in_button_attributes

Posted On : 2013-12-16 23:32:39
Satisfied : 3 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129558962
Reply This Thread
up-rate
6
down-rate
Comments
I would like to rate it 100, It´s working
profile Saksham Kumar - anyforum.in Saksham Kumar
734  339  39091
Posted On :2013-12-16 23:37:37.0
Leave a Comment

After reading the Google OAuth documentation and being frustrated by their lack of examples, this was the most helpful thing I found. Thank you so much!

Posted On : 2014-11-12 05:31:20
Satisfied : 0 Yes  0 No
profile Daniel Wilson - anyforum.in Daniel Wilson
000
Reply This Thread
up-rate
0
down-rate
Comments
My Pleasure Daniel Wilson!
profile Garima Gupta - anyforum.in Garima Gupta
596  1295  58962
Posted On :2014-11-12 13:45:34.0
Leave a Comment



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in