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: I want to add sign in with google on my website

I have registered the app for my website and i have Client ID but i am facing the problem while fetching the user´s information from google API. Thanks in advance.

google x 3
login x 5
Posted On : 2013-12-17 23:40:41.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939092
up-rate
5
down-rate

Answers


First off all you need to check that Google + API status is set to on or not. For this open https://cloud.google.com/console . 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. Next you have to follow the following step :

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

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>

-----------------------------------------------------------------------------------------------------------------------------------------

Posted On : 2013-12-17 23:58:50
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129558962
Reply This Thread
up-rate
5
down-rate



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