Skip to content

Instantly share code, notes, and snippets.

@dekz
Created May 12, 2011 04:16
Show Gist options
  • Save dekz/967917 to your computer and use it in GitHub Desktop.
Save dekz/967917 to your computer and use it in GitHub Desktop.
google api
clientID = ''
clientSecret = ''
redirectURI = 'urn:ietf:wg:oauth:2.0:oob'
code = ''
https = require 'https'
http = require 'http'
querystring = require 'querystring'
getRefreshToken = ->
body = querystring.stringify({ 'client_id' : clientID, 'client_secret': clientSecret, 'code': code, 'redirect_uri': redirectURI, 'grant_type': 'authorization_code'}, '&', '=')
options = {
host: 'www.google.com',
port: 443,
method: 'POST'
path: '/accounts/o8/oauth2/token',
headers: {
'Content-Length': body.length,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
req = https.request(options, (res) ->
status = res.statusCode
responseBody = ''
res.setEncoding('utf8')
res.on('data', (chunk) ->
responseBody += chunk
)
res.on('end', ->
console.log responseBody
)
)
req.write(body, 'utf8')
req.end()
getRefreshToken()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment