Friday, October 26, 2012

Get client ID for Google API using OAuth 2.0



Google updated its authentication system using OAuth 2.0.
 https://developers.google.com/accounts/docs/OAuth2

The previous code:
<script type="text/javascript">

function logMeIn() {
  scope = "https://www.google.com/
calendar/feeds/yourname%40gmail.com/";
      if (!google.accounts.user.

     checkLogin(scope)) {   
      var token = google.accounts.user.login(
scope,domain);
    }else
    {
        alert("You're logged in already!");
    }
}
</script>
should be changed to 
<script src="https://apis.google.com/js/client.js"></script>
<script type="text/javascript">
function logMeIn() {
    var config = {
    'client_id': 'your_id'
,
    'scope': 'https://www.googleapis.com/auth/calendar'
  };
  gapi.auth.authorize(config, function() {
    console.log(gapi.auth);
    console.log(gapi.auth.getToken().
access_token);
  });
}
</script>
 
So we need cliend_id in config to use Oauth 2.0. To get client_id
1) Login your Google account, go to
https://code.google.com/apis/console/.
2) Click on Create project…
3) Select Calendar API
for calendar application
4) Create API access, Create oauth 2.0 client ID
 
 


 

No comments:

Post a Comment