Thursday, 9 January 2014

Facebook Sign In Button


<script language="javascript" type="text/javascript">
    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    } (document));

    // Init the SDK upon load
    window.fbAsyncInit = function () {
        FB.init({
            appId: '680827721940158', // Write your own application id
            channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
            scope: 'id,name,gender,user_birthday,email,user_location,user_hometown',
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
            //,perms: 'user_address, user_mobile_phone'
        });
       

        // listen for and handle auth.statusChange events
        FB.Event.subscribe('auth.statusChange', function (response) {
            if (response.authResponse) {
                // user has auth'd your app and is logged into Facebook
                var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
                FB.api('/me', function (me) {
                    if (me.name) {
                        //me.name
                        document.getElementById('<%= txtNewFirstName.ClientID%>').value = me.first_name;
                        document.getElementById('<%= txtNewLastName.ClientID%>').value = me.last_name;
                        document.getElementById('<%= txtNewEmail.ClientID%>').value = me.email;

                        var location = me.location.name.split(',');

                        //For Country DropDown
                        var isCountry = false;
                        $("#<%=ddlNewCountry.ClientID%> option[selected]").removeAttr("selected");
                        var textToFind = location[1].trim();

                       me.languages[0].name.trim();
                       // $("#<%=ddlNewCountry.ClientID%>").val(location[1].trim());
                        //me.birthday;
                        // uid;
                        //me.gender;
                    }
                })
                document.getElementById('auth-loggedout').style.display = 'block';
                document.getElementById('auth-loggedin').style.display = 'block';
            } else {
                // user has not auth'd your app, or is not logged into Facebook
                document.getElementById('auth-loggedout').style.display = 'block';
                document.getElementById('auth-loggedin').style.display = 'none';
            }
        });
        $("#auth-logoutlink").click(function () { FB.logout(function () { window.location.reload(); }); });
    }
</script>

Create account in
http://developers.facebook.com/
create new application and please the url in web login(where to use)
Make sure that sandbox is disable.

Google Plus Sign In Button



<html>
<head>
  <title>Demo: Getting an email address using the Google+ Sign-in button</title>
  <style type="text/css">
  html, body { margin: 0; padding: 0; }
  .hide { display: none;}
  .show { display: block;}
  </style>
  <script type="text/javascript">
      /**
      * Global variables to hold the profile and email data.
      */
      var profile, email;

      /*
      * Triggered when the user accepts the sign in, cancels, or closes the
      * authorization dialog.
      */
      function loginFinishedCallback(authResult) {
          if (authResult) {
              if (authResult['error'] == undefined) {
                  toggleElement('signin-button'); // Hide the sign-in button after successfully signing in the user.
                  gapi.client.load('plus', 'v1', loadProfile);  // Trigger request to get the email address.
              } else {
                  console.log('An error occurred');
              }
          } else {
              console.log('Empty authResult');  // Something went wrong
          }
      }

      /**
      * Uses the JavaScript API to request the user's profile, which includes
      * their basic information. When the plus.profile.emails.read scope is
      * requested, the response will also include the user's primary email address
      * and any other email addresses that the user made public.
      */
      function loadProfile() {
          var request = gapi.client.plus.people.get({ 'userId': 'me' });
          request.execute(loadProfileCallback);
      }

      /**
      * Callback for the asynchronous request to the people.get method. The profile
      * and email are set to global variables. Triggers the user's basic profile
      * to display when called.
      */
      function loadProfileCallback(obj) {
          profile = obj;
          console.log(obj);

          // Filter the emails object to find the user's primary account, which might
          // not always be the first in the array. The filter() method supports IE9+.
          email = obj['emails'].filter(function (v) {
              return v.type === 'account'; // Filter out the primary email
          })[0].value; // get the email from the filtered results, should always be defined.
          displayProfile(profile);
      }

      /**
      * Display the user's basic profile information from the profile object.
      */
      function displayProfile(profile) {
          document.getElementById('name').innerHTML = profile['displayName'];
          document.getElementById('name').innerHTML = profile['name']['givenName'] + " - " + profile['name']['familyName'];
          document.getElementById('pic').innerHTML = '<img src="' + profile['image']['url'] + '" />';
          document.getElementById('email').innerHTML = email;

          if (profile['language'] == 'en')
              document.getElementById('launguage').innerHTML = "English";
          else
              document.getElementById('launguage').innerHTML = "French";

          if (profile['placesLived'][0].value != "undefine");
          document.getElementById('PlacesLived').innerHTML = profile['placesLived'][0].value;
         
          toggleElement('profile');
      }

      /**
      * Utility function to show or hide elements by their IDs.
      */
      function toggleElement(id) {
          var el = document.getElementById(id);
          if (el.getAttribute('class') == 'hide') {
              el.setAttribute('class', 'show');
          } else {
              el.setAttribute('class', 'hide');
          }
      }
  </script>
  <script src="https://apis.google.com/js/client:plusone.js" type="text/javascript"></script>
</head>
<body>
  <div id="signin-button" class="show">
     <div class="g-signin"
      data-callback="loginFinishedCallback"
      data-approvalprompt="force"
      data-clientid="656942774761-v378l3ad6pm3q6k3s0hrfbd4dl4tq4te.apps.googleusercontent.com"
      data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read"
      data-height="short"
      data-cookiepolicy="single_host_origin"
      >
    </div>
    <!-- In most cases, you don't want to use approvalprompt=force. Specified
    here to facilitate the demo.-->
  </div>

  <div id="profile" class="hide">
    <div>
      <span id="pic"></span>
      <span id="name"></span>
    </div>

    <div id="email"></div>
    <div id="launguage"></div>
    <div id="PlacesLived"></div>
  </div>
</body>
</html>


Create Project with this Link

https://cloud.google.com/console/project

Then Follow the step

APIs & auth Tab -->  CredentialsClient ID for web applicationEdit Settings of (Redirect URIs & Javascript Origins)  Here write url of your site where to use.