如何通过OAuth2和PassportJS获取Google Fitness API数据
我在使用Node和Express从Google Fitness API中获取数据以将其用于应用程序时遇到问题。这是app.js
的一部分:
app.get('/auth/google',
passport.authenticate('google',
{ scope: ['profile', '.activity.write'] }
));
app.get('/auth/google/redirect',
passport.authenticate('google'), (req, res) => {
res.json(req.user);
});
如您所见,我正在请求2个不同的范围。这是我使用passport-google-oauth20
的策略这是我针对passport.js
的特定数据点的策略:
passport.use(
new GoogleStrategy({
clientID: keys.google.clientID,
clientSecret: keys.google.clientSecret,
callbackURL:'http://localhost:3002/auth/google/redirect'
}, (accessToken, refreshToken, profile, done) => {
console.log(profile);
}
)
)
但是,问题在于,在控制台中,我仅获得具有所有属性的第一个作用域"profile"
,但是没有适合性的相关信息。知道有什么问题吗?我应该使用其他策略实施吗?目前,此代码已挂接到google的登录名,并且控制台记录了正常的个人资料信息。
有什么想法吗?谢谢。
回答如下:正确的范围是:fitness.activity.read
如何通过OAuth2和PassportJS获取Google Fitness API数据
我在使用Node和Express从Google Fitness API中获取数据以将其用于应用程序时遇到问题。这是app.js
的一部分:
app.get('/auth/google',
passport.authenticate('google',
{ scope: ['profile', '.activity.write'] }
));
app.get('/auth/google/redirect',
passport.authenticate('google'), (req, res) => {
res.json(req.user);
});
如您所见,我正在请求2个不同的范围。这是我使用passport-google-oauth20
的策略这是我针对passport.js
的特定数据点的策略:
passport.use(
new GoogleStrategy({
clientID: keys.google.clientID,
clientSecret: keys.google.clientSecret,
callbackURL:'http://localhost:3002/auth/google/redirect'
}, (accessToken, refreshToken, profile, done) => {
console.log(profile);
}
)
)
但是,问题在于,在控制台中,我仅获得具有所有属性的第一个作用域"profile"
,但是没有适合性的相关信息。知道有什么问题吗?我应该使用其他策略实施吗?目前,此代码已挂接到google的登录名,并且控制台记录了正常的个人资料信息。
有什么想法吗?谢谢。
回答如下:正确的范围是:fitness.activity.read