要求
:
我必须开发以下功能:用户在我的网站上单击一个按钮,然后弹出一个谷歌的对话框,请求我的应用程序在他的日历上有权限。如果用户接受了这一点,我的服务器应用程序(比如nodejs)应该可以随时读取他的事件(不只是30天)。
这是我试过的
:
我在学习这些教程(nodejs和browser)
https://developers.google.com/calendar/quickstart/nodejs
nodejs教程提供了我的帐户权限(而我需要用户授予他们的帐户权限)。
浏览器教程弹出对话框并请求权限。如果用户接受了请求,那么它在日历上的权限只会持续1小时(因此,即使我可以使用服务器上的令牌,它也不会解决问题)。检查一下,试着把承诺的结果打印出来
handleAuthClick
稍微修改一下
gapi.auth2.getAuthInstance().signIn().then(res => {console.log(res)});
查看打印结果中的过期时间:
{
"El": "117770076845340691060",
"Zi": {
"token_type": "Bearer",
"access_token": "ya29.Glb...zr8Yx",
"scope": "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email openid email profile",
"login_hint": "AJDLj...WlQ",
"expires_in": 3600,
"id_token": "eyJhvGciO...sHxw6HcA",
"session_state": {
"extraQueryParams": {
"authuser": "1"
}
},
"first_issued_at": 1528384733411,
"expires_at": 1528388333411,
"idpId": "google"
},
"w3": {
"Eea": "117770076845340691060",
"ig": "Bryan Gray",
"ofa": "Bryan",
"wea": "Gray",
"Paa": "https://lh3.googleusercontent.com/-zQ8KN1XZtJI/AAAAAAAAAAI/AAAAAAAAAAA/AB...e/s96-c/photo.jpg",
"U3": "alex@khealth.ai"
}
}