Skip to content

Instantly share code, notes, and snippets.

Created January 9, 2013 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4489908 to your computer and use it in GitHub Desktop.
Save anonymous/4489908 to your computer and use it in GitHub Desktop.
Google API meteor.js code
if Meteor.isClient
Meteor.subscribe "userinfo"
Session.set "foto", ""
Template.hello.greeting = ->
return "Welcome to glogin."
Template.login.foto = ->
f = Session.get "foto"
if f != ""
return f
else
return ""
Template.login.events
'click #btnLogin' : ->
console.log "Attempt Google login"
#https://www.googleapis.com/auth/calendar scope para calendar
Meteor.loginWithGoogle
requestPermissions: [
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/tasks'],
requestOfflineToken: true
->
getPerfilGoogle()
setCalendarEvent()
)
'click #btnLogout' : ->
console.log "logout"
Meteor.logout()
Template.hello.events
'click input' : ->
if console?
console.log("You pressed the button");
setCalendarEvent()
getPerfilGoogle = ->
url = "https://www.googleapis.com/oauth2/v1/userinfo";
params =
access_token: Meteor.user().services.google.accessToken,
part: "snippet",
mine: "true"
Meteor.http.get url, {params: params}, (err, result) ->
console.log result.data
Session.set "foto", result.data.picture
setCalendarEvent = ->
url = "https://www.googleapis.com/calendar/v3/calendars/primary/events"
console.log Meteor.user().services.google.accessToken
params =
access_token: Meteor.user().services.google.accessToken
Events:
summary: "Evento de prueba"
location: "Chiva, Valencia"
start:
"dateTime": "2013-01-10T10:00:00.000-07:00"
end:
"dateTime": "2013-01-10T11:00:00.000-07:00"
Meteor.http.post url, {params: params},
(err, result)->
console.log result.data
if Meteor.isServer
Meteor.startup ->
Meteor.publish "userinfo", ->
return Meteor.users.find({_id: this.userId}, {fields: {profile: 1, services: 1}})
testGoogle = ->
gapi.client.load 'calendar', 'v3', ->
console.log 'loaded.'
#gapi.client.setApiKey 'AIzaSyDe3u-N3m-lfVDuqAc0fpH2npB785uYgrQ'
evento =
summary: "Evento de prueba"
location: "Chiva, Valencia"
start:
"dateTime": "2011-12-16T10:00:00.000-07:00"
end:
"dateTime": "2011-12-16T11:00:00.000-07:00"
request = gapi.client.calendar.events.insert {'calendarId': 'primary', 'resource': evento}
request.execute (resp)->
console.log resp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment