使用Google帐户为使用Meteor应用注册的用户操作Google日历数据? [英] Manipulate Google Calendar data for users registered on Meteor app with a Google Account?

查看:120
本文介绍了使用Google帐户为使用Meteor应用注册的用户操作Google日历数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我想插入事件或至少发送事件邀请。我的用户使用Google帐户在我的应用中注册,但即使他们已注销,我也想插入这些事件。下面是我到目前为止的服务器代码,但它给了我权限不足的错误。

  if(user& & user.services&&& user.services.google&& 
user.services.google.accessToken){
var startTimeUTC = moment.utc(event.startTime,YYYY-MM -DD HH:mm:ss)。format();
var endTimeUTC = moment.utc(event.endTime,YYYY-MM-DD HH:mm:ss)。
console.log(POSTINGGCAL);
if(moment.utc()。unix()< moment.utc(event.endTime).unix()){
console.log(ENTERGCAL);
var id = Meteor.http.post(https://www.googleapis.com/calendar/v3/calendars/primary/events,{
'headers':{
' Authorization':Bearer+ user.services.google.accessToken,
'Content-Type':'application / json'
},
'data':{
摘要:event.name,
location:event.location,
start:{
dateTime:startTimeUTC,
},
end :{
dateTime:endTimeUTC,
},
参加者:[
{
email:user.email,
} ,
]
}
});
} //如果是时候就结束
} //结束如果用户

错误:

  W20141207-16:53:31.883(7)? (STDERR)
W20141207-16:53:31.883(7)? (STDERR)/Users/.meteor/packages/meteor-tool/.1.0.35.lzatbc++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib /node_modules/fibers/future.js:206
W20141207-16:53:31.884(7)? (STDERR)投掷(前);
W20141207-16:53:31.884(7)? (STDERR)^
W20141207-16:53:31.909(7)? (STDERR)错误:失败[403] {error:{errors:[{domain:global,reason:insufficientPermissions,message:Insufficient Permission}] :403,message:Permission Permission}}
W20141207-16:53:31.909(7)? (STDERR)在Object.Future.wait(/Users/.meteor/packages/meteor-tool/.1.0.35.lzatbc++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os。 osx.x86_64 / dev_bundle / lib / node_modules / fibers / future.js:326:15)
W20141207-16:53:31.910(7)? (STDERR)在Object.call(packages / meteor / helpers.js:118)
W20141207-16:53:31.910(7)? (STDERR)在Object.HTTP.post(packages / http / httpcall_common.js:56)
W20141207-16:53:31.910(7)? (STDERR)at scheduleIt(app / server / scheduler.js:243:28)
W20141207-16:53:31.910(7)? (STDERR)在app / server / startup.js:16:8
W20141207-16:53:31.911(7)? (STDERR)at _.extend.forEach(packages / mongo / mongo_driver.js:894)
W20141207-16:53:31.911(7)? (匿名函数)[for each]](packages / mongo / mongo_driver.js:741)
W20141207-16:53:31.911(7)? (STDERR)at app / server / startup.js:14:20
W20141207-16:53:31.912(7)? (STDERR)at _.extend.forEach(packages / mongo / mongo_driver.js:894)
W20141207-16:53:31.912(7)? (STDERR)在Cursor。(匿名函数)[for each]](packages / mongo / mongo_driver.js:741)
W20141207-16:53:31.912(7)? (STDERR) - - - - -
W20141207-16:53:31.913(7)? (STDERR)在makeErrorByStatus(packages / http / httpcall_common.js:12)
W20141207-16:53:31.913(7)? (STDERR)在Request._callback(packages / http / httpcall_server.js:95)
W20141207-16:53:31.913(7)? (STDERR)在Request.self.callback(/Users/.meteor/packages/http/.1.0.8.l3xm0k++os+web.browser+web.cordova/npm/node_modules/request/request.js:122: 22)
W20141207-16:53:31.913(7)? (STDERR)在Request.emit(events.js:98:17)
W20141207-16:53:31.914(7)? (STDERR)。< anonymous> (/Users/.meteor/packages/http/.1.0.8.l3xm0k++os+web.browser+web.cordova/npm/node_modules/request/request.js:888:14)
W20141207-16 :53:31.914(7)? (STDERR)在Request.emit(events.js:117:20)
W20141207-16:53:31.914(7)? (STDERR)在IncomingMessage。< anonymous> (/Users/.meteor/packages/http/.1.0.8.l3xm0k++os+web.browser+web.cordova/npm/node_modules/request/request.js:839:12)
W20141207-16 :53:31.914(7)? (STDERR)IncomingMessage.emit(events.js:117:20)
W20141207-16:53:31.915(7)? (STDERR)at _stream_readable.js:929:16
W20141207-16:53:31.915(7)? (STDERR)at process._tickCallback(node.js:419:13)
=>退出代码:8

编辑:我在客户端添加了以下内容,更长的时间收到任何错误,日历事件不会显示在我的测试Google帐户中。任何想法?

  Accounts.ui.config({
requestPermissions:{
google:
['https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.readonly',
'https:// www .googleapis.com / auth / userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth / tasks'],
// forceApprovalPrompt:{google:true}
},
forceApprovalPrompt:{google:true},
requestOfflineToken:{google:true},
passwordSignupFields:'EMAIL_ONLY',
// extraSignupFields:[]
});

继Meteor文档无法帮助,因为出现此错误:
Uncaught Error:Accounts。 ui.config:无效的键:forceApprovalPrompt

解决方案

从Google API中查看错误:

  insufficientPermissions 

这意味着令牌你使用的是通过要求用户只需登录w / o设置日历访问权限范围权限。



所以当你让用户登录,并且使用 Meteor.loginWithGoogle accounts-ui 包,您需要询问 Calendar API 范围:

  Meteor.loginWithGoogle({requestPermissions:['https://www.googleapis.com/auth/calendar'],forceApprovalPrompt:true})

或用于 accounts-ui

  Accou nts.ui.config({requestPermissions:{google:['https://www.googleapis.com/auth/calendar']},forceApprovalPrompt:{google:true}})


How do I manipulate Google Calendar data for users registered on my Meteor app with a Google Account?

For example, I want to insert events or at least send event invites. My users register on my app with a Google Account, but I want to insert the events even if they are logged out. Below is the server code I have so far, but it is giving me "insufficient permission" errors.

  if (user && user.services && user.services.google && 
        user.services.google.accessToken) {
    var startTimeUTC = moment.utc(event.startTime, "YYYY-MM-DD HH:mm:ss").format();
    var endTimeUTC = moment.utc(event.endTime, "YYYY-MM-DD HH:mm:ss").format();
    console.log("POSTINGGCAL");
    if (moment.utc().unix() < moment.utc(event.endTime).unix()) {
      console.log("ENTERGCAL");
      var id = Meteor.http.post("https://www.googleapis.com/calendar/v3/calendars/primary/events", {
        'headers' : { 
          'Authorization': "Bearer " + user.services.google.accessToken,
          'Content-Type': 'application/json' 
        },
        'data': {
          "summary": event.name,
          "location": event.location,
          "start": {
            "dateTime": startTimeUTC,
          },
          "end": {
            "dateTime": endTimeUTC,
          },
          "attendees": [
            {
              "email": user.email,
            },
          ]          
        }
      });
    }//end if moment
  }//end if user

Errors:

W20141207-16:53:31.883(7)? (STDERR) 
W20141207-16:53:31.883(7)? (STDERR) /Users/.meteor/packages/meteor-tool/.1.0.35.lzatbc++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:206
W20141207-16:53:31.884(7)? (STDERR)                         throw(ex);
W20141207-16:53:31.884(7)? (STDERR)                               ^
W20141207-16:53:31.909(7)? (STDERR) Error: failed [403] {  "error": {   "errors": [    {     "domain": "global",     "reason": "insufficientPermissions",     "message": "Insufficient Permission"    }   ],   "code": 403,   "message": "Insufficient Permission"  } } 
W20141207-16:53:31.909(7)? (STDERR)     at Object.Future.wait (/Users/.meteor/packages/meteor-tool/.1.0.35.lzatbc++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:326:15)
W20141207-16:53:31.910(7)? (STDERR)     at Object.call (packages/meteor/helpers.js:118)
W20141207-16:53:31.910(7)? (STDERR)     at Object.HTTP.post (packages/http/httpcall_common.js:56)
W20141207-16:53:31.910(7)? (STDERR)     at scheduleIt (app/server/scheduler.js:243:28)
W20141207-16:53:31.910(7)? (STDERR)     at app/server/startup.js:16:8
W20141207-16:53:31.911(7)? (STDERR)     at _.extend.forEach (packages/mongo/mongo_driver.js:894)
W20141207-16:53:31.911(7)? (STDERR)     at Cursor.(anonymous function) [as forEach] (packages/mongo/mongo_driver.js:741)
W20141207-16:53:31.911(7)? (STDERR)     at app/server/startup.js:14:20
W20141207-16:53:31.912(7)? (STDERR)     at _.extend.forEach (packages/mongo/mongo_driver.js:894)
W20141207-16:53:31.912(7)? (STDERR)     at Cursor.(anonymous function) [as forEach] (packages/mongo/mongo_driver.js:741)
W20141207-16:53:31.912(7)? (STDERR)     - - - - -
W20141207-16:53:31.913(7)? (STDERR)     at makeErrorByStatus (packages/http/httpcall_common.js:12)
W20141207-16:53:31.913(7)? (STDERR)     at Request._callback (packages/http/httpcall_server.js:95)
W20141207-16:53:31.913(7)? (STDERR)     at Request.self.callback (/Users/.meteor/packages/http/.1.0.8.l3xm0k++os+web.browser+web.cordova/npm/node_modules/request/request.js:122:22)
W20141207-16:53:31.913(7)? (STDERR)     at Request.emit (events.js:98:17)
W20141207-16:53:31.914(7)? (STDERR)     at Request.<anonymous> (/Users/.meteor/packages/http/.1.0.8.l3xm0k++os+web.browser+web.cordova/npm/node_modules/request/request.js:888:14)
W20141207-16:53:31.914(7)? (STDERR)     at Request.emit (events.js:117:20)
W20141207-16:53:31.914(7)? (STDERR)     at IncomingMessage.<anonymous> (/Users/.meteor/packages/http/.1.0.8.l3xm0k++os+web.browser+web.cordova/npm/node_modules/request/request.js:839:12)
W20141207-16:53:31.914(7)? (STDERR)     at IncomingMessage.emit (events.js:117:20)
W20141207-16:53:31.915(7)? (STDERR)     at _stream_readable.js:929:16
W20141207-16:53:31.915(7)? (STDERR)     at process._tickCallback (node.js:419:13)
=> Exited with code: 8

EDIT: I've added the following on the client, and while I no longer receive any errors, the calendar event is not showing up on my test Google account. Any ideas?

Accounts.ui.config({
    requestPermissions: {
        google: 
        ['https://www.googleapis.com/auth/calendar',
        'https://www.googleapis.com/auth/calendar.readonly',
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email',
        'https://www.googleapis.com/auth/tasks'],
//      forceApprovalPrompt: {google: true}
    }, 
    forceApprovalPrompt: {google: true},
    requestOfflineToken: {google: true},
    passwordSignupFields: 'EMAIL_ONLY',
//      extraSignupFields: []
});

Following Meteor docs not helping, as I get this error: Uncaught Error: Accounts.ui.config: Invalid key: forceApprovalPrompt

解决方案

Look at your error from Google APIs:

insufficientPermissions

This means that the token you used was achieved by asking the user just to login w/o setting calendar access to the scope permissions.

So when you let the user login, and you use Meteor.loginWithGoogle or accounts-ui package, you need to ask for the Calendar API scope:

Meteor.loginWithGoogle({requestPermissions: ['https://www.googleapis.com/auth/calendar'], forceApprovalPrompt: true})

or to be used with accounts-ui

Accounts.ui.config({requestPermissions:{google:['https://www.googleapis.com/auth/calendar']}, forceApprovalPrompt: {google: true}})

这篇关于使用Google帐户为使用Meteor应用注册的用户操作Google日历数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆