javascript - Use custom image for google signin button -
i want provide users facility sign in google. however, want use image(only image, no css) "sign in google" button. using following code:
<div id="mysignin"><img src="images/google.png" alt="google"/></div>
i using gapi.signin.render function mentioned on google developer console. code is:
<script src="https://apis.google.com/js/client:platform.js" type="text/javascript"></script> <script> function render(){ gapi.signin.render("mysignin", { // 'callback': 'signincallback', 'clientid': 'xxxx.apps.googleusercontent.com', 'cookiepolicy': 'single_host_origin', 'requestvisibleactions': 'http://schema.org/addaction', 'scope': 'profile' }); }
the problem google signin popup not opening , cannot figure out how solve it. please suggest. in advance.
<script type="text/javascript"> /** * handler signin callback triggered after user selects account. */ function onsignincallback(resp) { gapi.client.load('plus', 'v1', apiclientloaded); } /** * sets api call after google api client loads. */ function apiclientloaded() { gapi.client.plus.people.get({userid: 'me'}).execute(handleemailresponse); } /** * response callback when api client receives response. * * @param resp api response object user email , profile information. */ function handleemailresponse(resp) { var primaryemail; var jsonobj=json.stringify(resp);alert(jsonobj); var uid= jsonobj.id; var user_name1= jsonobj.name; (var i=0; < resp.emails.length; i++) { if (resp.emails[i].type === 'account') primaryemail = resp.emails[i].value; } /* document.getelementbyid('response').innerhtml = 'primary email: ' + primaryemail + '<br/>id is: ' + uid; */ }
to use image "google sign-in" button, can use googleauth.attachclickhandler() function google javascript sdk attach click handler image. replace <your-client-id>
app client id google developers console.
html example:
<html> <head> <meta name="google-signin-client_id" content="<your-client-id>.apps.googleusercontent.com.apps.googleusercontent.com"> </head> <body> <image id="googlesignin" src="img/your-icon.png"></image> <script src="https://apis.google.com/js/platform.js?onload=onloadgooglecallback" async defer></script> </body> </html>
javascript example:
function onloadgooglecallback(){ gapi.load('auth2', function() { auth2 = gapi.auth2.init({ client_id: '<your-client-id>.apps.googleusercontent.com', cookiepolicy: 'single_host_origin', scope: 'profile' }); auth2.attachclickhandler(element, {}, function(googleuser) { console.log('signed in: ' + googleuser.getbasicprofile().getname()); }, function(error) { console.log('sign-in error', error); } ); }); element = document.getelementbyid('googlesignin'); }
Comments
Post a Comment