पसंद के मुताबिक 'Google साइन इन' बटन बनाना

कस्टम सेटिंग वाला 'Google साइन-इन' बटन बनाने के लिए, अपने साइन इन पेज में 'साइन-इन करें' बटन शामिल करने वाला एलिमेंट जोड़ें. ऐसा फ़ंक्शन लिखें जो आपकी स्टाइल और स्कोप सेटिंग के साथ signin2.render() कॉल करता हो और क्वेरी स्ट्रिंग onload=YOUR_RENDER_FUNCTION के साथ https://apis.google.com/js/platform.js स्क्रिप्ट शामिल करें.

यहां 'Google साइन-इन' बटन का एक उदाहरण दिया गया है, जो कस्टम स्टाइल पैरामीटर के बारे में बताता है:

ऊपर दिए गए बटन को इन एचटीएमएल, JavaScript, और सीएसएस कोड से बनाया जाता है:

<html>
<head>
  <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
</head>
<body>
  <div id="my-signin2"></div>
  <script>
    function onSuccess(googleUser) {
      console.log('Logged in as: ' + googleUser.getBasicProfile().getName());
    }
    function onFailure(error) {
      console.log(error);
    }
    function renderButton() {
      gapi.signin2.render('my-signin2', {
        'scope': 'profile email',
        'width': 240,
        'height': 50,
        'longtitle': true,
        'theme': 'dark',
        'onsuccess': onSuccess,
        'onfailure': onFailure
      });
    }
  </script>

  <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
</body>
</html>

आपके पास 'Google साइन इन' बटन के लिए पसंद के मुताबिक सेटिंग तय करने का विकल्प भी है. इसके लिए, g-signin2 क्लास के साथ div एलिमेंट में data- एट्रिब्यूट की जानकारी दें. उदाहरण के लिए:

<div class="g-signin2" data-width="300" data-height="200" data-longtitle="true">

पसंद के मुताबिक ग्राफ़िक वाला बटन बनाना

अपनी साइट के डिज़ाइन के हिसाब से 'Google साइन इन' बटन बनाया जा सकता है. आपको ब्रैंडिंग के दिशा-निर्देशों का पालन करना होगा और अपने बटन में सही रंग और आइकॉन का इस्तेमाल करना होगा. ब्रैंडिंग के दिशा-निर्देशों में ऐसे आइकॉन एसेट भी दिए गए हैं जिनका इस्तेमाल करके बटन डिज़ाइन किया जा सकता है. आपको यह भी पक्का करना होगा कि आपका बटन, तीसरे पक्ष के लॉगिन के अन्य विकल्पों जितना ही प्रमुखता से दिखे.

कस्टम ग्राफ़िक की मदद से बनाए गए 'Google साइन इन' बटन का एक उदाहरण नीचे दिया गया है:

ऊपर दिए गए बटन को इन एचटीएमएल, JavaScript, और सीएसएस कोड से बनाया जाता है:

<html>
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
  <script src="https://apis.google.com/js/api:client.js"></script>
  <script>
  var googleUser = {};
  var startApp = function() {
    gapi.load('auth2', function(){
      // Retrieve the singleton for the GoogleAuth library and set up the client.
      auth2 = gapi.auth2.init({
        client_id: 'YOUR_CLIENT_ID.apps.googleusercontent.com',
        cookiepolicy: 'single_host_origin',
        // Request scopes in addition to 'profile' and 'email'
        //scope: 'additional_scope'
      });
      attachSignin(document.getElementById('customBtn'));
    });
  };

  function attachSignin(element) {
    console.log(element.id);
    auth2.attachClickHandler(element, {},
        function(googleUser) {
          document.getElementById('name').innerText = "Signed in: " +
              googleUser.getBasicProfile().getName();
        }, function(error) {
          alert(JSON.stringify(error, undefined, 2));
        });
  }
  </script>
  <style type="text/css">
    #customBtn {
      display: inline-block;
      background: white;
      color: #444;
      width: 190px;
      border-radius: 5px;
      border: thin solid #888;
      box-shadow: 1px 1px 1px grey;
      white-space: nowrap;
    }
    #customBtn:hover {
      cursor: pointer;
    }
    span.label {
      font-family: serif;
      font-weight: normal;
    }
    span.icon {
      background: url('/identity/sign-in/g-normal.png') transparent 5px 50% no-repeat;
      display: inline-block;
      vertical-align: middle;
      width: 42px;
      height: 42px;
    }
    span.buttonText {
      display: inline-block;
      vertical-align: middle;
      padding-left: 42px;
      padding-right: 42px;
      font-size: 14px;
      font-weight: bold;
      /* Use the Roboto font that is loaded in the <head> */
      font-family: 'Roboto', sans-serif;
    }
  </style>
  </head>
  <body>
  <!-- In the callback, you would hide the gSignInWrapper element on a
  successful sign in -->
  <div id="gSignInWrapper">
    <span class="label">Sign in with:</span>
    <div id="customBtn" class="customGPlusSignIn">
      <span class="icon"></span>
      <span class="buttonText">Google</span>
    </div>
  </div>
  <div id="name"></div>
  <script>startApp();</script>
</body>
</html>